mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Use basePullAt in _.remove.
This commit is contained in:
@@ -1780,12 +1780,12 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.at` without support for strings and individual
|
||||
* key arguments.
|
||||
* The base implementation of `_.at` without support for string collections
|
||||
* and individual key arguments.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object} collection The collection to iterate over.
|
||||
* @param {number[]|string[]} [props] The property names or indexes of elements to pick.
|
||||
* @param {number[]|string[]} props The property names or indexes of elements to pick.
|
||||
* @returns {Array} Returns the new array of picked elements.
|
||||
*/
|
||||
function baseAt(collection, props) {
|
||||
@@ -2598,6 +2598,27 @@
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.pullAt` without support for individual
|
||||
* index arguments and capturing the removed elements.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} array The array to modify.
|
||||
* @param {number[]} indexes The indexes of elements to remove.
|
||||
* @returns {Array} Returns `array`.
|
||||
*/
|
||||
function basePullAt(array, indexes) {
|
||||
var length = indexes.length;
|
||||
while (length--) {
|
||||
var index = parseFloat(indexes[length]);
|
||||
if (index != previous && isIndex(index)) {
|
||||
var previous = index;
|
||||
splice.call(array, index, 1);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.random` without support for argument juggling
|
||||
* and returning floating-point numbers.
|
||||
@@ -5254,17 +5275,8 @@
|
||||
array || (array = []);
|
||||
indexes = baseFlatten(indexes);
|
||||
|
||||
var length = indexes.length,
|
||||
result = baseAt(array, indexes);
|
||||
|
||||
indexes.sort(baseCompareAscending);
|
||||
while (length--) {
|
||||
var index = parseFloat(indexes[length]);
|
||||
if (index != previous && isIndex(index)) {
|
||||
var previous = index;
|
||||
splice.call(array, index, 1);
|
||||
}
|
||||
}
|
||||
var result = baseAt(array, indexes);
|
||||
basePullAt(array, indexes.sort(baseCompareAscending));
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -5308,34 +5320,23 @@
|
||||
* // => [2, 4]
|
||||
*/
|
||||
function remove(array, predicate, thisArg) {
|
||||
var result = [];
|
||||
if (!(array && array.length)) {
|
||||
return result;
|
||||
}
|
||||
var index = -1,
|
||||
length = array ? array.length : 0,
|
||||
result = [],
|
||||
removes = 0,
|
||||
indexes = [],
|
||||
last;
|
||||
length = array.length;
|
||||
|
||||
predicate = getCallback(predicate, thisArg, 3);
|
||||
while (++index < length) {
|
||||
var value = array[index];
|
||||
if (predicate(value, index, array)) {
|
||||
if (last && last[0] + last[1] === index) {
|
||||
++last[1];
|
||||
} else {
|
||||
last = [index - removes, 1];
|
||||
indexes.push(last);
|
||||
}
|
||||
result.push(value);
|
||||
++removes;
|
||||
indexes.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
index = -1;
|
||||
length = indexes.length;
|
||||
while (++index < length) {
|
||||
last = indexes[index];
|
||||
splice.call(array, last[0], last[1]);
|
||||
}
|
||||
basePullAt(array, indexes);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user