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