Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

atlas-median

1.0.1 • Public • Published

atlas-median

Calculates the median of a set of data points in-place.

Travis


install

npm install --save atlas-median

why

Breaking up atlas-dataset into standalone functions. This module computes the median value over an array of numbers:

median(V) = (v[ceil(|V|/2)] + v[ceil((|V|+1)/2)])/2

examples

unsorted array

The median function sorts the array in-place before taking the middle value. In the case of an even-length array, the median is the mean of the two middle values.

const median = require("atlas-median")
console.log(median([4,3,1,2]))
// 2.5

sorted array

To avoid sorting a pre-sorted array, use a boolean flag:

...
const isSorted = true;
console.log(median([1,2,3,4,5], isSorted)) // fast
// 3

Install

npm i atlas-median

DownloadsWeekly Downloads

6

Version

1.0.1

License

Apache-2.0

Unpacked Size

3.8 kB

Total Files

6

Last publish

Collaborators

  • avatar