source: node_modules/es-toolkit/dist/compat/array/pullAllWith.js@ ba17441

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

Added visualizations

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