aggregatejs

0.0.5 • Public • Published

aggregatejs Build Status Coverage Status npm version

A set of statistical and mathematical aggregation functions written in JavaScript.

Installation

$ npm install aggregatejs

Example

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
 

API

All aggregate functions are returning a value based on array of numbers:

average

Returns the average of the numbers in array.

let value = average([100, -100, 150, -50, 100, 250]);
// => 75

count

Counts the numbers in array.

let value = count([100, -100, 150, -50, 100, 250]);
// => 6

max

Returns the largest number in array.

let value = max([100, -100, 150, -50, 250, 100]);
// => 250

min

Returns the smallest number in array.

let value = min([100, -100, 150, -50, 250, 100]);
// => -100

percentile

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

sum

Returns the sum of all numbers in array.

let value = sum([100, -100, 150, -50, 100, 250]);
// => 450

median

Returns the median of the numbers in array.

let value = median([100, -100, 150, -50, 100, 250]);
// => 100

variance

Returns the variance population of the numbers in array.

let value = variance([2, 4, 4, 4, 5, 5, 7, 9]);
// => 4

deviation

Returns the standard deviation of the numbers in array.

let value = deviation([2, 4, 4, 4, 5, 5, 7, 9]);
// => 2

Running tests

$ npm test

License

MIT

Package Sidebar

Install

npm i aggregatejs

Weekly Downloads

6

Version

0.0.5

License

MIT

Last publish

Collaborators

  • yefremov