mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
Ensure basePullAt works with deep paths.
This commit is contained in:
21
lodash.js
21
lodash.js
@@ -765,7 +765,7 @@
|
||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||
);
|
||||
|
||||
/** Native method and object references. */
|
||||
/** Native value references. */
|
||||
var ArrayBuffer = context.ArrayBuffer,
|
||||
Reflect = context.Reflect,
|
||||
Set = getNative(context, 'Set'),
|
||||
@@ -2412,14 +2412,25 @@
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function basePullAt(array, indexes) {
|
||||
var length = array ? indexes.length : 0;
|
||||
var length = array ? indexes.length : 0,
|
||||
lastIndex = length - 1;
|
||||
|
||||
while (length--) {
|
||||
var index = indexes[length];
|
||||
if (index != previous) {
|
||||
if (lastIndex == length || index != previous) {
|
||||
var previous = index;
|
||||
if (isIndex(index)) {
|
||||
splice.call(array, index, 1);
|
||||
} else {
|
||||
}
|
||||
else if (!isKey(index, array)) {
|
||||
var path = toPath(index),
|
||||
object = path.length == 1 ? array : baseGet(array, baseSlice(path, 0, -1));
|
||||
|
||||
if (object != null) {
|
||||
delete object[last(path)];
|
||||
}
|
||||
}
|
||||
else {
|
||||
delete array[index];
|
||||
}
|
||||
}
|
||||
@@ -4787,7 +4798,7 @@
|
||||
* // => [10, 20]
|
||||
*/
|
||||
var pullAt = restParam(function(array, indexes) {
|
||||
indexes = baseFlatten(indexes);
|
||||
indexes = arrayMap(baseFlatten(indexes), String);
|
||||
|
||||
var result = baseAt(array, indexes);
|
||||
basePullAt(array, indexes.sort(compareAscending));
|
||||
|
||||
@@ -12372,9 +12372,10 @@
|
||||
});
|
||||
|
||||
test('should work with a falsey `array` argument when keys are provided', 1, function() {
|
||||
var expected = _.map(falsey, _.constant(Array(4)));
|
||||
var values = falsey.slice(),
|
||||
expected = _.map(values, _.constant(Array(4)));
|
||||
|
||||
var actual = _.map(falsey, function(array) {
|
||||
var actual = _.map(values, function(array) {
|
||||
try {
|
||||
return _.pullAt(array, 0, 1, 'pop', 'push');
|
||||
} catch(e) {}
|
||||
|
||||
Reference in New Issue
Block a user