A set of statistical and mathematical aggregation functions written in JavaScript.
$ npm install aggregatejs
import { 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]);
// => 75
All 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]);
// => 75
Counts the numbers in array
.
let value = count([100, -100, 150, -50, 100, 250]);
// => 6
Returns the largest number in array
.
let value = max([100, -100, 150, -50, 250, 100]);
// => 250
Returns the smallest number in array
.
let value = min([100, -100, 150, -50, 250, 100]);
// => -100
Returns 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);
// => 225
Returns the sum of all numbers in array
.
let value = sum([100, -100, 150, -50, 100, 250]);
// => 450
Returns the median of the numbers in array
.
let value = median([100, -100, 150, -50, 100, 250]);
// => 100
Returns the variance population of the numbers in array
.
let value = variance([2, 4, 4, 4, 5, 5, 7, 9]);
// => 4
Returns the standard deviation of the numbers in array
.
let value = deviation([2, 4, 4, 4, 5, 5, 7, 9]);
// => 2
$ npm test