UNPKG

832 BJavaScriptView Raw
1/**
2 * The base implementation of methods like `_.max` and `_.min` which accepts a
3 * `comparator` to determine the extremum value.
4 *
5 * @private
6 * @param {Array} array The array to iterate over.
7 * @param {Function} iteratee The iteratee invoked per iteration.
8 * @param {Function} comparator The comparator used to compare values.
9 * @returns {*} Returns the extremum value.
10 */
11function baseExtremum(array, iteratee, comparator) {
12 var index = -1,
13 length = array.length;
14
15 while (++index < length) {
16 var value = array[index],
17 current = iteratee(value);
18
19 if (current != null && (computed === undefined
20 ? current === current
21 : comparator(current, computed)
22 )) {
23 var computed = current,
24 result = value;
25 }
26 }
27 return result;
28}
29
30export default baseExtremum;