1 var baseEach = require('./baseEach');
3 /** Used as references for `-Infinity` and `Infinity`. */
4 var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
5 POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
8 * Gets the extremum value of `collection` invoking `iteratee` for each value
9 * in `collection` to generate the criterion by which the value is ranked.
10 * The `iteratee` is invoked with three arguments: (value, index, collection).
13 * @param {Array|Object|string} collection The collection to iterate over.
14 * @param {Function} iteratee The function invoked per iteration.
15 * @param {boolean} [isMin] Specify returning the minimum, instead of the
16 * maximum, extremum value.
17 * @returns {*} Returns the extremum value.
19 function extremumBy(collection, iteratee, isMin) {
20 var exValue = isMin ? POSITIVE_INFINITY : NEGATIVE_INFINITY,
24 baseEach(collection, function(value, index, collection) {
25 var current = iteratee(value, index, collection);
26 if ((isMin ? (current < computed) : (current > computed)) ||
27 (current === exValue && current === result)) {
35 module.exports = extremumBy;