mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Bump to v3.9.0.
This commit is contained in:
@@ -1,37 +1,31 @@
|
||||
var baseCallback = require('./baseCallback'),
|
||||
charAtCallback = require('./charAtCallback'),
|
||||
extremumBy = require('./extremumBy'),
|
||||
isArray = require('../lang/isArray'),
|
||||
var arrayExtremum = require('./arrayExtremum'),
|
||||
baseCallback = require('./baseCallback'),
|
||||
baseExtremum = require('./baseExtremum'),
|
||||
isIterateeCall = require('./isIterateeCall'),
|
||||
isString = require('../lang/isString'),
|
||||
toIterable = require('./toIterable');
|
||||
|
||||
/**
|
||||
* Creates a `_.max` or `_.min` function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} arrayFunc The function to get the extremum value from an array.
|
||||
* @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
|
||||
* extremum value.
|
||||
* @param {Function} comparator The function used to compare values.
|
||||
* @param {*} exValue The initial extremum value.
|
||||
* @returns {Function} Returns the new extremum function.
|
||||
*/
|
||||
function createExtremum(arrayFunc, isMin) {
|
||||
function createExtremum(comparator, exValue) {
|
||||
return function(collection, iteratee, thisArg) {
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
var noIteratee = iteratee == null;
|
||||
|
||||
iteratee = noIteratee ? iteratee : baseCallback(iteratee, thisArg, 3);
|
||||
if (noIteratee) {
|
||||
var isArr = isArray(collection);
|
||||
if (!isArr && isString(collection)) {
|
||||
iteratee = charAtCallback;
|
||||
} else {
|
||||
return arrayFunc(isArr ? collection : toIterable(collection));
|
||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||
if (iteratee.length == 1) {
|
||||
collection = toIterable(collection);
|
||||
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
||||
if (!(collection.length && result === exValue)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return extremumBy(collection, iteratee, isMin);
|
||||
return baseExtremum(collection, iteratee, comparator, exValue);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user