ml-arrayxy-uniquex
Advanced tools
Comparing version 0.0.2 to 0.2.4
{ | ||
"name": "ml-arrayxy-uniquex", | ||
"version": "0.0.2", | ||
"version": "0.2.4", | ||
"description": "Function to sum the y values if the x values are equals. The x array has to be ordered.", | ||
"main": "./src/index.js", | ||
"main": "lib/index.js", | ||
"module": "src/index.js", | ||
"files": [ | ||
"lib", | ||
"src" | ||
@@ -17,3 +19,3 @@ ], | ||
"type": "git", | ||
"url": "https://github.com/mljs/arrayxy-uniquex.git" | ||
"url": "https://github.com/mljs/array-xy.git" | ||
}, | ||
@@ -30,14 +32,7 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/mljs/arrayxy-uniquex/issues" | ||
"url": "https://github.com/mljs/array-xy/issues" | ||
}, | ||
"tonicExampleFilename": "./tonic.js", | ||
"homepage": "https://github.com/mljs/arrayxy-uniquex#readme", | ||
"devDependencies": { | ||
"eslint": "^3.4.0", | ||
"eslint-config-cheminfo": "^1.1.2", | ||
"eslint-plugin-no-only-tests": "^1.1.0", | ||
"mocha": "^3.0.2", | ||
"mocha-better-spec-reporter": "^3.0.2", | ||
"should": "^11.1.0" | ||
} | ||
"homepage": "https://github.com/mljs/array-sy/#readme", | ||
"gitHead": "34f9f1559ca636dde9f676ddac73b4aee0dcbefa" | ||
} |
@@ -1,34 +0,34 @@ | ||
'use strict'; | ||
/** | ||
* In place modification of the 2 arrays to make X unique and sum the Y if X has the same value | ||
* @param xs | ||
* @param ys | ||
* @param {object} [points={}] : Object of points contains property x (an array) and y (an array) | ||
* @return points | ||
*/ | ||
function uniqueX(xs, ys) { | ||
if (xs.length < 2) return; | ||
export default function uniqueX(points = {}) { | ||
const { x, y } = points; | ||
if (x.length < 2) return; | ||
if (x.length !== y.length) { | ||
throw new Error('The X and Y arrays mush have the same length'); | ||
} | ||
var current = xs[0]; | ||
var counter = 0; | ||
let current = x[0]; | ||
let counter = 0; | ||
for (var i = 1; i < xs.length; i++) { | ||
if (current !== xs[i]) { | ||
counter++; | ||
current = xs[i]; | ||
xs[counter] = xs[i]; | ||
if (i !== counter) { | ||
ys[counter] = 0; | ||
} | ||
} | ||
if (i !== counter) { | ||
ys[counter] += ys[i]; | ||
} | ||
for (let i = 1; i < x.length; i++) { | ||
if (current !== x[i]) { | ||
counter++; | ||
current = x[i]; | ||
x[counter] = x[i]; | ||
if (i !== counter) { | ||
y[counter] = 0; | ||
} | ||
} | ||
if (i !== counter) { | ||
y[counter] += y[i]; | ||
} | ||
} | ||
xs.length = counter + 1; | ||
ys.length = counter + 1; | ||
x.length = counter + 1; | ||
y.length = counter + 1; | ||
} | ||
module.exports = uniqueX; |
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
6644
0
7
84
1
40
2