@daeinc/array
Advanced tools
Comparing version 0.3.0 to 0.3.1
/** | ||
* accumulate array values. ex. [50,50,50] => [50,100,150] | ||
* | ||
* TEST: float rounding error needs more testing | ||
* | ||
* @param arr | ||
* @returns | ||
*/ | ||
export declare const accumulate: (arr: number[]) => number[]; | ||
export declare const accumulate: (arr: number[], precision?: number) => number[]; | ||
/** | ||
@@ -8,0 +11,0 @@ * add to array in-place while limiting how many to keep history. |
@@ -7,10 +7,14 @@ "use strict"; | ||
* accumulate array values. ex. [50,50,50] => [50,100,150] | ||
* | ||
* TEST: float rounding error needs more testing | ||
* | ||
* @param arr | ||
* @returns | ||
*/ | ||
const accumulate = (arr) => { | ||
const accumulate = (arr, precision = 4) => { | ||
const result = []; | ||
let sum = 0; | ||
for (let i = 0; i < arr.length; i++) { | ||
sum += arr[i]; | ||
sum = sum + (0, math_1.roundF)(arr[i], 4); | ||
sum = (0, math_1.roundF)(sum, 4); | ||
result.push(sum); | ||
@@ -17,0 +21,0 @@ } |
{ | ||
"name": "@daeinc/array", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Array utilities", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13418
226