SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-04-19 22:17:16 -07:00
define(['./_baseExtremum', './_baseGt', './_baseIteratee'], function(baseExtremum, baseGt, baseIteratee) {
2015-12-16 17:53:20 -08:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* This method is like `_.max` except that it accepts `iteratee` which is
* invoked for each element in `array` to generate the criterion by which
* the value is ranked. The iteratee is invoked with one argument: (value).
*
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 4.0.0
2015-12-16 17:53:20 -08:00
* @category Math
* @param {Array} array The array to iterate over.
2016-07-24 09:52:04 -07:00
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
2015-12-16 17:53:20 -08:00
* @returns {*} Returns the maximum value.
* @example
*
* var objects = [{ 'n': 1 }, { 'n': 2 }];
*
2016-01-24 18:06:10 -08:00
* _.maxBy(objects, function(o) { return o.n; });
2015-12-16 17:53:20 -08:00
* // => { 'n': 2 }
*
2016-02-01 23:13:04 -08:00
* // The `_.property` iteratee shorthand.
2015-12-16 17:53:20 -08:00
* _.maxBy(objects, 'n');
* // => { 'n': 2 }
*/
function maxBy(array, iteratee) {
return (array && array.length)
2016-07-24 09:52:04 -07:00
? baseExtremum(array, baseIteratee(iteratee, 2), baseGt)
2015-12-16 17:53:20 -08:00
: undefined;
}
return maxBy;
});