mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Ensure _.indexOf and _.lastIndexOf return -1 when performing a binary search for undefined and it's not found. [closes #1303]
This commit is contained in:
@@ -5089,10 +5089,9 @@
|
|||||||
if (typeof fromIndex == 'number') {
|
if (typeof fromIndex == 'number') {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
||||||
} else if (fromIndex) {
|
} else if (fromIndex) {
|
||||||
var index = binaryIndex(array, value),
|
var index = binaryIndex(array, value);
|
||||||
other = array[index];
|
if (index < length &&
|
||||||
|
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
|
||||||
if (value === value ? (value === other) : (other !== other)) {
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -9354,12 +9354,13 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should return `-1` for an unmatched value', 4, function() {
|
test('`_.' + methodName + '` should return `-1` for an unmatched value', 5, function() {
|
||||||
var array = [1, 2, 3],
|
var array = [1, 2, 3],
|
||||||
empty = [];
|
empty = [];
|
||||||
|
|
||||||
strictEqual(func(array, 4), -1);
|
strictEqual(func(array, 4), -1);
|
||||||
strictEqual(func(array, 4, true), -1);
|
strictEqual(func(array, 4, true), -1);
|
||||||
|
strictEqual(func(array, undefined, true), -1);
|
||||||
|
|
||||||
strictEqual(func(empty, undefined), -1);
|
strictEqual(func(empty, undefined), -1);
|
||||||
strictEqual(func(empty, undefined, true), -1);
|
strictEqual(func(empty, undefined, true), -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user