mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import arrayMap from './.internal/arrayMap.js';
|
|
import baseIndexOf from './.internal/baseIndexOf.js';
|
|
import baseIndexOfWith from './.internal/baseIndexOfWith.js';
|
|
import copyArray from './.internal/copyArray.js';
|
|
|
|
/** Built-in value references. */
|
|
const splice = Array.prototype.splice;
|
|
|
|
/**
|
|
* The base implementation of `pullAllBy`.
|
|
*
|
|
* @private
|
|
* @param {Array} array The array to modify.
|
|
* @param {Array} values The values to remove.
|
|
* @param {Function} [iteratee] The iteratee invoked per element.
|
|
* @param {Function} [comparator] The comparator invoked per element.
|
|
* @returns {Array} Returns `array`.
|
|
*/
|
|
function basePullAll(array, values, iteratee, comparator) {
|
|
const indexOf = comparator ? baseIndexOfWith : baseIndexOf;
|
|
const length = values.length;
|
|
|
|
let index = -1;
|
|
let seen = array;
|
|
|
|
if (array === values) {
|
|
values = copyArray(values);
|
|
}
|
|
if (iteratee) {
|
|
seen = arrayMap(array, value => iteratee(value));
|
|
}
|
|
while (++index < length) {
|
|
let fromIndex = 0;
|
|
const value = values[index];
|
|
const computed = iteratee ? iteratee(value) : value;
|
|
|
|
while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
|
|
if (seen !== array) {
|
|
splice.call(seen, fromIndex, 1);
|
|
}
|
|
splice.call(array, fromIndex, 1);
|
|
}
|
|
}
|
|
return array;
|
|
}
|
|
|
|
export default basePullAll;
|