mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Bump to v3.0.0.
This commit is contained in:
38
internal/createExtremum.js
Normal file
38
internal/createExtremum.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import charAtCallback from './charAtCallback';
|
||||
import extremumBy from './extremumBy';
|
||||
import isArray from '../lang/isArray';
|
||||
import isIterateeCall from './isIterateeCall';
|
||||
import isString from '../lang/isString';
|
||||
import toIterable from './toIterable';
|
||||
|
||||
/**
|
||||
* Creates a function that gets the extremum value of a collection.
|
||||
*
|
||||
* @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.
|
||||
* @returns {Function} Returns the new extremum function.
|
||||
*/
|
||||
function createExtremum(arrayFunc, isMin) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
return extremumBy(collection, iteratee, isMin);
|
||||
};
|
||||
}
|
||||
|
||||
export default createExtremum;
|
||||
Reference in New Issue
Block a user