Let the nullish check be handled by baseCallback.

This commit is contained in:
John-David Dalton
2014-12-28 17:21:13 -06:00
parent 3f8dd7e658
commit f7d306cb02

View File

@@ -4811,8 +4811,8 @@
* // => 1 * // => 1
*/ */
function sortedIndex(array, value, iteratee, thisArg) { function sortedIndex(array, value, iteratee, thisArg) {
iteratee = iteratee == null ? iteratee : getCallback(iteratee, thisArg, 1); iteratee = getCallback(iteratee, thisArg, 1);
return binaryIndex(array, value, iteratee); return binaryIndex(array, value, iteratee === identity ? null : iteratee);
} }
/** /**
@@ -4837,8 +4837,8 @@
* // => 4 * // => 4
*/ */
function sortedLastIndex(array, value, iteratee, thisArg) { function sortedLastIndex(array, value, iteratee, thisArg) {
iteratee = iteratee == null ? iteratee : getCallback(iteratee, thisArg, 1); iteratee = getCallback(iteratee, thisArg, 1);
return binaryIndex(array, value, iteratee, true); return binaryIndex(array, value, iteratee === identity ? null : iteratee, true);
} }
/** /**
@@ -5085,10 +5085,10 @@
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
isSorted = false; isSorted = false;
} }
iteratee = iteratee == null iteratee = getCallback(iteratee, thisArg, 3);
? iteratee if (iteratee === identity) {
: getCallback(iteratee, thisArg, 3); iteratee = null;
}
return (isSorted && getIndexOf() == baseIndexOf) return (isSorted && getIndexOf() == baseIndexOf)
? sortedUniq(array, iteratee) ? sortedUniq(array, iteratee)
: baseUniq(array, iteratee); : baseUniq(array, iteratee);
@@ -5989,20 +5989,22 @@
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null; iteratee = null;
} }
var noIteratee = iteratee == null, iteratee = getCallback(iteratee, thisArg, 3);
var noIteratee = iteratee === identity,
isArr = noIteratee && isArray(collection), isArr = noIteratee && isArray(collection),
isStr = !isArr && isString(collection); isStr = !isArr && isString(collection);
if (noIteratee && !isStr) { if (noIteratee) {
return arrayMax(isArr ? collection : toIterable(collection)); if (isStr) {
iteratee = charAtCallback;
} else {
return arrayMax(isArr ? collection : toIterable(collection));
}
} }
var computed = NEGATIVE_INFINITY, var computed = NEGATIVE_INFINITY,
result = computed; result = computed;
iteratee = (noIteratee && isStr)
? charAtCallback
: getCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, index, collection) { baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection); var current = iteratee(value, index, collection);
if (current > computed || (current === NEGATIVE_INFINITY && current === result)) { if (current > computed || (current === NEGATIVE_INFINITY && current === result)) {
@@ -6060,20 +6062,22 @@
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) { if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null; iteratee = null;
} }
var noIteratee = iteratee == null, iteratee = getCallback(iteratee, thisArg, 3);
var noIteratee = iteratee === identity,
isArr = noIteratee && isArray(collection), isArr = noIteratee && isArray(collection),
isStr = !isArr && isString(collection); isStr = !isArr && isString(collection);
if (noIteratee && !isStr) { if (noIteratee) {
return arrayMin(isArr ? collection : toIterable(collection)); if (isStr) {
iteratee = charAtCallback;
} else {
return arrayMin(isArr ? collection : toIterable(collection));
}
} }
var computed = POSITIVE_INFINITY, var computed = POSITIVE_INFINITY,
result = computed; result = computed;
iteratee = (noIteratee && isStr)
? charAtCallback
: getCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, index, collection) { baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection); var current = iteratee(value, index, collection);
if (current < computed || (current === POSITIVE_INFINITY && current === result)) { if (current < computed || (current === POSITIVE_INFINITY && current === result)) {
@@ -8744,7 +8748,7 @@
* *
* // using "_.pluck" callback shorthand * // using "_.pluck" callback shorthand
* _.mapValues(users, 'age'); * _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/ */
function mapValues(object, iteratee, thisArg) { function mapValues(object, iteratee, thisArg) {
iteratee = getCallback(iteratee, thisArg, 3); iteratee = getCallback(iteratee, thisArg, 3);