UNPKG

614 BJavaScriptView Raw
1import isArray from './is-array';
2/**
3 * @param {Array} arr The array to iterate over.
4 * @return {*} Returns the minimum value.
5 * @example
6 *
7 * min([1, 2]);
8 * // => 1
9 *
10 * min([]);
11 * // => undefined
12 *
13 * const data = new Array(1250010).fill(1).map((d,idx) => idx);
14 *
15 * min(data);
16 * // => 1250010
17 * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
18 */
19export default (function (arr) {
20 if (!isArray(arr)) {
21 return undefined;
22 }
23 return arr.reduce(function (prev, curr) {
24 return Math.min(prev, curr);
25 }, arr[0]);
26});
27//# sourceMappingURL=min.js.map
\No newline at end of file