Files
lodash/minBy.js
2017-01-09 17:38:33 -08:00

29 lines
801 B
JavaScript

import baseExtremum from './_baseExtremum.js';
import baseLt from './_baseLt.js';
/**
* This method is like `min` 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
* @since 4.0.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {*} Returns the minimum value.
* @example
*
* var objects = [{ 'n': 1 }, { 'n': 2 }];
*
* minBy(objects, function(o) { return o.n; });
* // => { 'n': 1 }
*/
function minBy(array, iteratee) {
return (array && array.length)
? baseExtremum(array, iteratee, baseLt)
: undefined;
}
export default minBy;