UNPKG

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