Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atlassubbed/atlas-median
https://github.com/atlassubbed/atlas-median
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/atlassubbed/atlas-median
- Owner: atlassubbed
- License: other
- Created: 2018-07-16T02:22:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-16T02:47:33.000Z (over 6 years ago)
- Last Synced: 2024-11-05T18:15:03.008Z (2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# atlas-median
Calculates the median of a set of data points in-place.
[![Travis](https://img.shields.io/travis/atlassubbed/atlas-median.svg)](https://travis-ci.org/atlassubbed/atlas-median)
---
## install
```
npm install --save atlas-median
```## why
Breaking up [atlas-dataset](https://github.com/atlassubbed/atlas-dataset#readme) into standalone functions. This module computes the median value over an array of numbers:
## 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.
```javascript
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:
```javascript
...
const isSorted = true;
console.log(median([1,2,3,4,5], isSorted)) // fast
// 3
```