Ensure _.at and _.pullAt work with falsey array and collection values when keys are provided.

This commit is contained in:
John-David Dalton
2014-10-23 00:41:30 -07:00
parent 1fb92df2e7
commit 2060f3f59a
2 changed files with 25 additions and 1 deletions

View File

@@ -3999,7 +3999,7 @@
* // => [10, 20]
*/
function pullAt(array) {
return basePullAt(array, baseFlatten(arguments, false, false, 1));
return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
}
/**

View File

@@ -953,6 +953,18 @@
deepEqual(actual, ['d', 'a', 'c']);
});
test('should work with a falsey `array` argument when keys are provided', 1, function() {
var expected = _.map(falsey, _.constant([undefined, undefined]));
var actual = _.map(falsey, function(value) {
try {
return _.at(value, 0, 1);
} catch(e) {}
});
deepEqual(actual, expected);
});
test('should work with an `arguments` object for `collection`', 1, function() {
var actual = _.at(args, [2, 0]);
deepEqual(actual, ['c', 'a']);
@@ -9184,6 +9196,18 @@
deepEqual(actual, ['d', 'a', 'c']);
});
test('should work with a falsey `array` argument when keys are provided', 1, function() {
var expected = _.map(falsey, _.constant([undefined, undefined]));
var actual = _.map(falsey, function(value) {
try {
return _.pullAt(value, 0, 1);
} catch(e) {}
});
deepEqual(actual, expected);
});
test('should ignore non-index values', 2, function() {
var array = ['a', 'b', 'c'],
clone = array.slice();