Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

maxBy.js 991B

12345678910111213141516171819202122232425262728293031323334
  1. var baseExtremum = require('./_baseExtremum'),
  2. baseGt = require('./_baseGt'),
  3. baseIteratee = require('./_baseIteratee');
  4. /**
  5. * This method is like `_.max` except that it accepts `iteratee` which is
  6. * invoked for each element in `array` to generate the criterion by which
  7. * the value is ranked. The iteratee is invoked with one argument: (value).
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 4.0.0
  12. * @category Math
  13. * @param {Array} array The array to iterate over.
  14. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15. * @returns {*} Returns the maximum value.
  16. * @example
  17. *
  18. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  19. *
  20. * _.maxBy(objects, function(o) { return o.n; });
  21. * // => { 'n': 2 }
  22. *
  23. * // The `_.property` iteratee shorthand.
  24. * _.maxBy(objects, 'n');
  25. * // => { 'n': 2 }
  26. */
  27. function maxBy(array, iteratee) {
  28. return (array && array.length)
  29. ? baseExtremum(array, baseIteratee(iteratee, 2), baseGt)
  30. : undefined;
  31. }
  32. module.exports = maxBy;