A set of statistical and mathematical aggregation functions written in JavaScript.
$ npm install aggregatejsimport { max, min } from 'aggregatejs';
// top-level exports can be imported individually (recommended)
import percentile from 'aggregatejs/percentile';
import average from 'aggregatejs/average';
max([100, -100, 150, -50, 250, 100]);
// => 250
min([100, -100, 150, -50, 250, 100]);
// => -100
percentile([100, -100, 150, -50, 100, 250], 0.25);
// => -12.5
average([100, -100, 150, -50, 100, 250]);
// => 75All aggregate functions are returning a value based on array of numbers:
Returns the average of the numbers in array.
let value = average([100, -100, 150, -50, 100, 250]);
// => 75Counts the numbers in array.
let value = count([100, -100, 150, -50, 100, 250]);
// => 6Returns the largest number in array.
let value = max([100, -100, 150, -50, 250, 100]);
// => 250Returns the smallest number in array.
let value = min([100, -100, 150, -50, 250, 100]);
// => -100Returns the k-th percentile of values in array.
let perc25 = percentile([100, -100, 150, -50, 100, 250], 0.25);
// => -12.5
let perc50 = percentile([100, -100, 150, -50, 100, 250], 0.50);
// => 100
let perc95 = percentile([100, -100, 150, -50, 100, 250], 0.95);
// => 225Returns the sum of all numbers in array.
let value = sum([100, -100, 150, -50, 100, 250]);
// => 450Returns the median of the numbers in array.
let value = median([100, -100, 150, -50, 100, 250]);
// => 100Returns the variance population of the numbers in array.
let value = variance([2, 4, 4, 4, 5, 5, 7, 9]);
// => 4Returns the standard deviation of the numbers in array.
let value = deviation([2, 4, 4, 4, 5, 5, 7, 9]);
// => 2$ npm test