deno.land / x / simplestatistic@v7.7.1 / src / min.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
/** * The min is the lowest number in the 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 * @throws {Error} if the length of x is less than one * @returns {number} minimum value * @example * min([1, 5, -10, 100, 2]); // => -10 */function min(x) { if (x.length === 0) { throw new Error("min requires at least one data point"); }
let value = x[0]; for (let i = 1; i < x.length; i++) { if (x[i] < value) { value = x[i]; } } return value;}
export default min;
simplestatistic

Version Info

Tagged at
2 years ago