Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ml-spectra-processing

Package Overview
Dependencies
Maintainers
6
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-spectra-processing - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

src/x/boxPlot.js

9

History.md

@@ -0,1 +1,10 @@

# [0.4.0](https://github.com/cheminfo/spectra-processing/compare/v0.3.0...v0.4.0) (2019-10-01)
### Features
* add X.boxPlot ([3a1f0ea](https://github.com/cheminfo/spectra-processing/commit/3a1f0ea))
# [0.3.0](https://github.com/cheminfo/spectra-processing/compare/v0.2.0...v0.3.0) (2019-08-30)

@@ -2,0 +11,0 @@

92

lib/index.js

@@ -633,18 +633,5 @@ 'use strict';

/**
* This function performs a circular shift to a new array
* Positive values of shifts will shift to the right and negative values will do to the left
* @example rotate([1,2,3,4],1) -> [4,1,2,3]
* @example rotate([1,2,3,4],-1) -> [2,3,4,1]
* @param {Array} array - the array that will be rotated
* @param {number} shift
* @return {Array}
*/
function rotate(array, shift) {
shift = shift % array.length;
if (shift < 0) shift += array.length;
return array.slice(array.length - shift).concat(array.slice(0, array.length - shift));
}
/**
* This function subtract the first array by the second array or a constant value from each element of the first array
* This function add the first array by the second array or a constant value to each element of the first array
* @param {Array} array1 - the array that will be rotated

@@ -654,3 +641,3 @@ * @param {Array|Number} array2

*/
function subtract(array1, array2) {
function add(array1, array2) {
let isConstant = false;

@@ -668,7 +655,7 @@ let constant;

for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] - constant;
array3[i] = array1[i] + constant;
}
} else {
for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] - array2[i];
array3[i] = array1[i] + array2[i];
}

@@ -681,5 +668,38 @@ }

/**
* This function subtract the first array by the second array or a constant value from each element of the first array
* @param {Array} array1 - the array that will be rotated
* @return {object}
*/
function boxPlot(array) {
array = array.slice(0).sort((a, b) => a - b);
if (array.length < 5) {
throw Error('boxPlot: can not calculate info if array contains less than 3 elements');
}
let info = { Q1: 0.0, Q2: 0.0, Q3: 0.0, min: array[0], max: array[array.length - 1] };
let q1max, q3min;
if (array.length % 2 === 1) { // odd
let middle = (array.length - 1) / 2;
info.Q2 = array[middle];
q1max = middle - 1;
q3min = middle + 1;
} else { // even
q3min = array.length / 2;
q1max = q3min - 1;
info.Q2 = (array[q1max] + array[q3min]) / 2;
}
if (q1max % 2 === 0) {
info.Q1 = array[q1max / 2];
info.Q3 = array[(array.length + q3min - 1) / 2];
} else {
info.Q1 = (array[(q1max + 1) / 2] + array[(q1max - 1) / 2]) / 2;
let middleOver = (array.length + q3min) / 2;
info.Q3 = (array[middleOver] + array[middleOver - 1]) / 2;
}
return info;
}
/**
* This function add the first array by the second array or a constant value to each element of the first array
/**
* This function divide the first array by the second array or a constant value to each element of the first array
* @param {Array} array1 - the array that will be rotated

@@ -689,3 +709,3 @@ * @param {Array|Number} array2

*/
function add(array1, array2) {
function divide(array1, array2) {
let isConstant = false;

@@ -703,7 +723,7 @@ let constant;

for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] + constant;
array3[i] = array1[i] / constant;
}
} else {
for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] + array2[i];
array3[i] = array1[i] / array2[i];
}

@@ -748,5 +768,18 @@ }

/**
* This function performs a circular shift to a new array
* Positive values of shifts will shift to the right and negative values will do to the left
* @example rotate([1,2,3,4],1) -> [4,1,2,3]
* @example rotate([1,2,3,4],-1) -> [2,3,4,1]
* @param {Array} array - the array that will be rotated
* @param {number} shift
* @return {Array}
*/
function rotate(array, shift) {
shift = shift % array.length;
if (shift < 0) shift += array.length;
return array.slice(array.length - shift).concat(array.slice(0, array.length - shift));
}
/**
* This function divide the first array by the second array or a constant value to each element of the first array
* This function subtract the first array by the second array or a constant value from each element of the first array
* @param {Array} array1 - the array that will be rotated

@@ -756,3 +789,3 @@ * @param {Array|Number} array2

*/
function divide(array1, array2) {
function subtract(array1, array2) {
let isConstant = false;

@@ -770,7 +803,7 @@ let constant;

for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] / constant;
array3[i] = array1[i] - constant;
}
} else {
for (let i = 0; i < array1.length; i++) {
array3[i] = array1[i] / array2[i];
array3[i] = array1[i] - array2[i];
}

@@ -783,9 +816,10 @@ }

const X = {
add,
boxPlot,
divide,
findClosestIndex,
getTargetIndex,
multiply,
rotate,
subtract,
add,
multiply,
divide,
getTargetIndex,
};

@@ -792,0 +826,0 @@

{
"name": "ml-spectra-processing",
"version": "0.3.0",
"version": "0.4.0",
"description": "Various method to process spectra",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -0,17 +1,19 @@

import { add } from './add';
import { boxPlot } from './boxPlot';
import { divide } from './divide';
import { findClosestIndex } from './findClosestIndex';
import { getTargetIndex } from './getTargetIndex';
import { multiply } from './multiply';
import { rotate } from './rotate';
import { subtract } from './subtract';
import { add } from './add';
import { multiply } from './multiply';
import { divide } from './divide';
import { getTargetIndex } from './getTargetIndex';
export const X = {
add,
boxPlot,
divide,
findClosestIndex,
getTargetIndex,
multiply,
rotate,
subtract,
add,
multiply,
divide,
getTargetIndex,
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc