summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/lodash/internal/arrayExtremum.js
blob: e45badbda1be069ca1151c389d3674942f32f7fb (plain)
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
27
28
29
30
/**
 * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
 * with one argument: (value).
 *
 * @private
 * @param {Array} array The array to iterate over.
 * @param {Function} iteratee The function invoked per iteration.
 * @param {Function} comparator The function used to compare values.
 * @param {*} exValue The initial extremum value.
 * @returns {*} Returns the extremum value.
 */
function arrayExtremum(array, iteratee, comparator, exValue) {
  var index = -1,
      length = array.length,
      computed = exValue,
      result = computed;

  while (++index < length) {
    var value = array[index],
        current = +iteratee(value);

    if (comparator(current, computed)) {
      computed = current;
      result = value;
    }
  }
  return result;
}

module.exports = arrayExtremum;