main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
797 bytes
|
Line | |
---|
1 | var _curry1 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry1.js");
|
---|
4 |
|
---|
5 | var mean =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./mean.js");
|
---|
8 | /**
|
---|
9 | * Returns the median of the given list of numbers.
|
---|
10 | *
|
---|
11 | * @func
|
---|
12 | * @memberOf R
|
---|
13 | * @since v0.14.0
|
---|
14 | * @category Math
|
---|
15 | * @sig [Number] -> Number
|
---|
16 | * @param {Array} list
|
---|
17 | * @return {Number}
|
---|
18 | * @see R.mean
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * R.median([2, 9, 7]); //=> 7
|
---|
22 | * R.median([7, 2, 10, 9]); //=> 8
|
---|
23 | * R.median([]); //=> NaN
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | var median =
|
---|
28 | /*#__PURE__*/
|
---|
29 | _curry1(function median(list) {
|
---|
30 | var len = list.length;
|
---|
31 |
|
---|
32 | if (len === 0) {
|
---|
33 | return NaN;
|
---|
34 | }
|
---|
35 |
|
---|
36 | var width = 2 - len % 2;
|
---|
37 | var idx = (len - width) / 2;
|
---|
38 | return mean(Array.prototype.slice.call(list, 0).sort(function (a, b) {
|
---|
39 | return a < b ? -1 : a > b ? 1 : 0;
|
---|
40 | }).slice(idx, idx + width));
|
---|
41 | });
|
---|
42 |
|
---|
43 | module.exports = median; |
---|
Note:
See
TracBrowser
for help on using the repository browser.