From 790d6331f8f3313730286be83fc00da449210e02 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 25 Aug 2015 23:12:12 -0700 Subject: [PATCH] Remove `fromIndex` type check from `_.includes`. --- lodash.js | 2 +- test/test.js | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lodash.js b/lodash.js index 22824aa5b..848161a5f 100644 --- a/lodash.js +++ b/lodash.js @@ -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); diff --git a/test/test.js b/test/test.js index 7ffca4a66..15f08d341 100644 --- a/test/test.js +++ b/test/test.js @@ -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); });