Ignore isSorted if _.indexOf is customized.

This commit is contained in:
John-David Dalton
2014-07-13 00:26:27 -07:00
parent f7330cce14
commit 12f04650de
2 changed files with 9 additions and 4 deletions

View File

@@ -2397,11 +2397,12 @@
} }
var index = -1, var index = -1,
indexOf = getIndexOf(), indexOf = getIndexOf(),
prereq = !isSorted && indexOf === baseIndexOf, prereq = indexOf === baseIndexOf,
isLarge = prereq && createCache && length >= 200, isLarge = prereq && createCache && length >= 200,
isCommon = prereq && !isLarge, isCommon = prereq && !isLarge,
result = []; result = [];
isSorted = prereq && isSorted;
if (isLarge) { if (isLarge) {
var seen = createCache(); var seen = createCache();
indexOf = cacheIndexOf; indexOf = cacheIndexOf;

View File

@@ -4527,11 +4527,15 @@
} }
}); });
test('`_.uniq` should work with a custom `_.indexOf` method', 2, function() { test('`_.uniq` should work with a custom `_.indexOf` method', 6, function() {
if (!isModularize) { if (!isModularize) {
_.indexOf = custom; _.indexOf = custom;
deepEqual(_.uniq(array), array.slice(0, 3));
deepEqual(_.uniq(largeArray), [largeArray[0]]); _.each([false, true, _.identity], function(param) {
deepEqual(_.uniq(array, param), array.slice(0, 3));
deepEqual(_.uniq(largeArray, param), [largeArray[0]]);
});
_.indexOf = indexOf; _.indexOf = indexOf;
} }
else { else {