https://github.com/yefremov/aggregatejs
Aggregate functions returning single result based on groups of data
https://github.com/yefremov/aggregatejs
aggregate browser functions nodejs utilities
Last synced: 3 months ago
JSON representation
Aggregate functions returning single result based on groups of data
- Host: GitHub
- URL: https://github.com/yefremov/aggregatejs
- Owner: yefremov
- License: mit
- Created: 2017-02-17T10:33:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-27T19:39:45.000Z (over 8 years ago)
- Last Synced: 2025-09-18T08:59:26.605Z (4 months ago)
- Topics: aggregate, browser, functions, nodejs, utilities
- Language: JavaScript
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# aggregatejs [](https://travis-ci.org/yefremov/aggregatejs) [](https://coveralls.io/github/yefremov/aggregatejs?branch=master) [](https://badge.fury.io/js/aggregatejs)
A set of statistical and mathematical aggregation functions written in JavaScript.
## Installation
```bash
$ npm install aggregatejs
```
## Example
```js
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`.
```js
let value = average([100, -100, 150, -50, 100, 250]);
// => 75
```
### count
Counts the numbers in `array`.
```js
let value = count([100, -100, 150, -50, 100, 250]);
// => 6
```
### max
Returns the largest number in `array`.
```js
let value = max([100, -100, 150, -50, 250, 100]);
// => 250
```
### min
Returns the smallest number in `array`.
```js
let value = min([100, -100, 150, -50, 250, 100]);
// => -100
```
### percentile
Returns the `k`-th percentile of values in `array`.
```js
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`.
```js
let value = sum([100, -100, 150, -50, 100, 250]);
// => 450
```
### median
Returns the median of the numbers in `array`.
```js
let value = median([100, -100, 150, -50, 100, 250]);
// => 100
```
### variance
Returns the variance population of the numbers in `array`.
```js
let value = variance([2, 4, 4, 4, 5, 5, 7, 9]);
// => 4
```
### deviation
Returns the standard deviation of the numbers in `array`.
```js
let value = deviation([2, 4, 4, 4, 5, 5, 7, 9]);
// => 2
```
## Running tests
```bash
$ npm test
```
## License
[MIT](LICENSE)