Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createExtremum.js
1 var arrayExtremum = require('./arrayExtremum'),
2     baseCallback = require('./baseCallback'),
3     baseExtremum = require('./baseExtremum'),
4     isArray = require('../lang/isArray'),
5     isIterateeCall = require('./isIterateeCall'),
6     toIterable = require('./toIterable');
7
8 /**
9  * Creates a `_.max` or `_.min` function.
10  *
11  * @private
12  * @param {Function} comparator The function used to compare values.
13  * @param {*} exValue The initial extremum value.
14  * @returns {Function} Returns the new extremum function.
15  */
16 function createExtremum(comparator, exValue) {
17   return function(collection, iteratee, thisArg) {
18     if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
19       iteratee = undefined;
20     }
21     iteratee = baseCallback(iteratee, thisArg, 3);
22     if (iteratee.length == 1) {
23       collection = isArray(collection) ? collection : toIterable(collection);
24       var result = arrayExtremum(collection, iteratee, comparator, exValue);
25       if (!(collection.length && result === exValue)) {
26         return result;
27       }
28     }
29     return baseExtremum(collection, iteratee, comparator, exValue);
30   };
31 }
32
33 module.exports = createExtremum;