mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Ensure _.pullAt ignores non-index values.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
21
test/test.js
21
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);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user