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