This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
StasisWarden-Legacy/node_modules/es-toolkit/dist/compat/array/pullAllWith.mjs
T

34 lines
989 B
JavaScript

import copyArray from '../_internal/copyArray.mjs';
import { eq } from '../util/eq.mjs';
function pullAllWith(array, values, comparator) {
if (array?.length == null || values?.length == null) {
return array;
}
if (array === values) {
values = copyArray(values);
}
let resultLength = 0;
if (comparator == null) {
comparator = (a, b) => eq(a, b);
}
const valuesArray = Array.isArray(values) ? values : Array.from(values);
const hasUndefined = valuesArray.includes(undefined);
for (let i = 0; i < array.length; i++) {
if (i in array) {
const shouldRemove = valuesArray.some(value => comparator(array[i], value));
if (!shouldRemove) {
array[resultLength++] = array[i];
}
continue;
}
if (!hasUndefined) {
delete array[resultLength++];
}
}
array.length = resultLength;
return array;
}
export { pullAllWith };