mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Ensure _.pullAt ignores non-index values.
This commit is contained in:
@@ -2983,8 +2983,8 @@
|
|||||||
|
|
||||||
indexes.sort(baseCompareAscending);
|
indexes.sort(baseCompareAscending);
|
||||||
while (length--) {
|
while (length--) {
|
||||||
var index = indexes[length];
|
var index = parseFloat(indexes[length]);
|
||||||
if (index != previous) {
|
if (index != previous && index > -1 && index % 1 == 0) {
|
||||||
var previous = index;
|
var previous = index;
|
||||||
splice.call(array, index, 1);
|
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() {
|
test('should work with unsorted indexes', 2, function() {
|
||||||
var array = [1, 2, 3, 4, 5],
|
var array = [1, 2, 3, 4],
|
||||||
actual = _.pullAt(array, [4, 1, 0, 3]);
|
actual = _.pullAt(array, [1, 3, 0]);
|
||||||
|
|
||||||
deepEqual(array, [3]);
|
deepEqual(array, [3]);
|
||||||
deepEqual(actual, [5, 2, 1, 4]);
|
deepEqual(actual, [2, 4, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with repeated indexes', 2, function() {
|
test('should work with repeated indexes', 2, function() {
|
||||||
@@ -7316,6 +7316,21 @@
|
|||||||
deepEqual(array, ['b']);
|
deepEqual(array, ['b']);
|
||||||
deepEqual(actual, ['d', 'a', 'c']);
|
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