source: node_modules/es-toolkit/dist/compat/array/pullAllWith.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import copyArray from '../_internal/copyArray.mjs';
2import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
3
4function pullAllWith(array, values, comparator) {
5 if (array?.length == null || values?.length == null) {
6 return array;
7 }
8 if (array === values) {
9 values = copyArray(values);
10 }
11 let resultLength = 0;
12 if (comparator == null) {
13 comparator = (a, b) => isEqualsSameValueZero(a, b);
14 }
15 const valuesArray = Array.isArray(values) ? values : Array.from(values);
16 const hasUndefined = valuesArray.includes(undefined);
17 for (let i = 0; i < array.length; i++) {
18 if (i in array) {
19 const shouldRemove = valuesArray.some(value => comparator(array[i], value));
20 if (!shouldRemove) {
21 array[resultLength++] = array[i];
22 }
23 continue;
24 }
25 if (!hasUndefined) {
26 delete array[resultLength++];
27 }
28 }
29 array.length = resultLength;
30 return array;
31}
32
33export { pullAllWith };
Note: See TracBrowser for help on using the repository browser.