From 32167b45cef7e9b73c9ecd310de0980a0ae962c6 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 7 May 2014 00:12:12 -0700 Subject: [PATCH] Ensure `_.pullAt` ignores non-index values. --- lodash.js | 4 ++-- test/test.js | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index e171a2a70..e9e7dea6c 100644 --- a/lodash.js +++ b/lodash.js @@ -2983,8 +2983,8 @@ indexes.sort(baseCompareAscending); while (length--) { - var index = indexes[length]; - if (index != previous) { + var index = parseFloat(indexes[length]); + if (index != previous && index > -1 && index % 1 == 0) { var previous = index; splice.call(array, index, 1); } diff --git a/test/test.js b/test/test.js index f60bd7a10..1a6ff086d 100644 --- a/test/test.js +++ b/test/test.js @@ -7278,11 +7278,11 @@ }); test('should work with unsorted indexes', 2, function() { - var array = [1, 2, 3, 4, 5], - actual = _.pullAt(array, [4, 1, 0, 3]); + var array = [1, 2, 3, 4], + actual = _.pullAt(array, [1, 3, 0]); deepEqual(array, [3]); - deepEqual(actual, [5, 2, 1, 4]); + deepEqual(actual, [2, 4, 1]); }); test('should work with repeated indexes', 2, function() { @@ -7316,6 +7316,21 @@ deepEqual(array, ['b']); deepEqual(actual, ['d', 'a', 'c']); }); + + test('should ignore non-index values', 2, function() { + var array = ['a', 'b', 'c'], + clone = array.slice(); + + var values = _.reject(empties, function(value) { + return value === 0 || _.isArray(value); + }).concat(-1, 1.1); + + var expected = _.map(values, _.constant(undefined)), + actual = _.pullAt.apply(_, [array].concat(values)); + + deepEqual(actual, expected); + deepEqual(array, clone); + }); }()); /*--------------------------------------------------------------------------*/