Remove fromIndex type check from _.includes.

This commit is contained in:
John-David Dalton
2015-08-25 23:12:12 -07:00
parent 9121ab95ea
commit 790d6331f8
2 changed files with 5 additions and 7 deletions

View File

@@ -6117,7 +6117,7 @@
function includes(collection, target, fromIndex, guard) {
collection = isArrayLike(collection) ? collection : values(collection);
var length = collection.length;
if (guard || typeof fromIndex != 'number') {
if (guard || !fromIndex) {
fromIndex = 0;
} else {
fromIndex = toInteger(fromIndex);

View File

@@ -5572,8 +5572,10 @@
deepEqual(actual, expected);
});
test('should work with ' + key + ' and treat non-number `fromIndex` values as `0`', 1, function() {
strictEqual(_.includes(collection, values[0], '1'), true);
test('should work with ' + key + ' and coerce non-integer `fromIndex` values to integers', 3, function() {
strictEqual(_.includes(collection, values[0], '1'), false);
strictEqual(_.includes(collection, values[0], 0.1), true);
strictEqual(_.includes(collection, values[0], NaN), true);
});
test('should work with ' + key + ' and a negative `fromIndex`', 2, function() {
@@ -5633,10 +5635,6 @@
deepEqual(actual, expected);
});
test('should not be possible to perform a binary search', 1, function() {
strictEqual(_.includes([3, 2, 1], 3, true), true);
});
test('should match `NaN`', 1, function() {
strictEqual(_.includes([1, NaN, 3], NaN), true);
});