1 | import quantile from "./quantile";
|
2 |
|
3 | /**
|
4 | * The [median](http://en.wikipedia.org/wiki/Median) is
|
5 | * the middle number of a list. This is often a good indicator of 'the middle'
|
6 | * when there are outliers that skew the `mean()` value.
|
7 | * This is a [measure of central tendency](https://en.wikipedia.org/wiki/Central_tendency):
|
8 | * a method of finding a typical or central value of a set of numbers.
|
9 | *
|
10 | * The median isn't necessarily one of the elements in the list: the value
|
11 | * can be the average of two elements if the list has an even length
|
12 | * and the two central values are different.
|
13 | *
|
14 | * @param {Array<number>} x input
|
15 | * @returns {number} median value
|
16 | * @example
|
17 | * median([10, 2, 5, 100, 2, 1]); // => 3.5
|
18 | */
|
19 | function median(x) {
|
20 | return +quantile(x, 0.5);
|
21 | }
|
22 |
|
23 | export default median;
|