@newdash/newdash
Version:
javascript/typescript utility library
45 lines (44 loc) • 1.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const baseIndexOf_1 = __importDefault(require("./baseIndexOf"));
const baseIndexOfWith_1 = __importDefault(require("./baseIndexOfWith"));
const copyArray_1 = __importDefault(require("./copyArray"));
const baseUnary_1 = __importDefault(require("./baseUnary"));
const arrayMap_1 = __importDefault(require("./arrayMap"));
/**
* @ignore
*/
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 {any} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns `array`.
*/
function basePullAll(array, values, iteratee, comparator) {
var indexOf = comparator ? baseIndexOfWith_1.default : baseIndexOf_1.default, index = -1, length = values.length, seen = array;
if (array === values) {
values = (0, copyArray_1.default)(values);
}
if (iteratee) {
seen = (0, arrayMap_1.default)(array, (0, baseUnary_1.default)(iteratee));
}
while (++index < length) {
var fromIndex = 0, value = values[index], 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;
}
exports.default = basePullAll;