Cleanup createExtremum.

This commit is contained in:
John-David Dalton
2014-12-30 18:37:45 -06:00
parent 3d2b6b7620
commit d555241d03

View File

@@ -3055,15 +3055,15 @@
} }
/** /**
* Creates a function that retrieves the extremum value of a collection. * Creates a function that gets the extremum value of a collection.
* *
* @private * @private
* @param {Function} exFunc The function to retrieve the extremum value. * @param {Function} arrayFunc The function to get the extremum value from an array.
* @param {boolean} [isMin] Specify returning the minimum, instead of the * @param {boolean} [isMin] Specify returning the minimum, instead of the maximum,
* maximum, extremum value. * extremum value.
* @returns {Function} Returns the new extremum function. * @returns {Function} Returns the new extremum function.
*/ */
function createExtremum(exFunc, isMin) { function createExtremum(arrayFunc, isMin) {
return function(collection, iteratee, thisArg) { return function(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null; iteratee = null;
@@ -3075,14 +3075,12 @@
noIteratee = false; noIteratee = false;
iteratee = func(iteratee, thisArg, 3); iteratee = func(iteratee, thisArg, 3);
} }
var isArr = noIteratee && isArray(collection),
isStr = !isArr && isString(collection);
if (noIteratee) { if (noIteratee) {
if (isStr) { var isArr = isArray(collection);
if (!isArr && isString(collection)) {
iteratee = charAtCallback; iteratee = charAtCallback;
} else { } else {
return exFunc(isArr ? collection : toIterable(collection)); return arrayFunc(isArr ? collection : toIterable(collection));
} }
} }
return extremumBy(collection, iteratee, isMin); return extremumBy(collection, iteratee, isMin);