deno.land / x / simplestatistic@v7.7.1 / src / extent.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/** * This computes the minimum & maximum number in an array. * * This runs in `O(n)`, linear time, with respect to the length of the array. * * @param {Array<number>} x sample of one or more data points * @returns {Array<number>} minimum & maximum value * @throws {Error} if the length of x is less than one * @example * extent([1, 2, 3, 4]); * // => [1, 4] */function extent(x) { if (x.length === 0) { throw new Error("extent requires at least one data point"); }
let min = x[0]; let max = x[0]; for (let i = 1; i < x.length; i++) { if (x[i] > max) { max = x[i]; } if (x[i] < min) { min = x[i]; } } return [min, max];}
export default extent;
simplestatistic

Version Info

Tagged at
2 years ago