mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Ensure _.indexOf and _.lastIndexOf match NaN when performing a binary search.
This commit is contained in:
@@ -3683,8 +3683,10 @@
|
||||
if (typeof fromIndex == 'number') {
|
||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||
} else if (fromIndex) {
|
||||
var index = sortedIndex(array, value);
|
||||
return array[index] === value ? index : -1;
|
||||
var index = sortedIndex(array, value),
|
||||
other = array[index];
|
||||
|
||||
return (value === value ? value === other : other !== other) ? index : -1;
|
||||
}
|
||||
return baseIndexOf(array, value, fromIndex);
|
||||
}
|
||||
@@ -3821,7 +3823,8 @@
|
||||
index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
|
||||
} else if (fromIndex) {
|
||||
index = sortedLastIndex(array, value) - 1;
|
||||
return array[index] === value ? index : -1;
|
||||
var other = array[index];
|
||||
return (value === value ? value === other : other !== other) ? index : -1;
|
||||
}
|
||||
if (value !== value) {
|
||||
return indexOfNaN(array, index, true);
|
||||
|
||||
@@ -7066,8 +7066,9 @@
|
||||
strictEqual(func(empty, undefined, true), -1);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should match `NaN`', 1, function() {
|
||||
test('`_.' + methodName + '` should match `NaN`', 2, function() {
|
||||
strictEqual(func([1, NaN, 3], NaN), 1);
|
||||
strictEqual(func([1, 3, NaN], NaN, true), 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user