maxBy source npm

_.maxBy(array, [iteratee=_.identity])

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).

Arguments

  1. array (Array)

    The array to iterate over.

  2. [iteratee=_.identity] (Function|Object|string)

    The function invoked per element.

Returns (*)

Returns the maximum value.

Example

var users = [
  { 'user': 'barney', 'age': 36 },
  { 'user': 'fred',   'age': 40 }
];

_.maxBy(users, function(o) { return o.age; });
// => { 'user': 'fred', 'age': 40 }

// using the `_.property` callback shorthand
_.maxBy(users, 'age');
// => { 'user': 'fred', 'age': 40 }