|
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.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const copyArray = require('../_internal/copyArray.js');
|
|---|
| 6 | const isEqualsSameValueZero = require('../../_internal/isEqualsSameValueZero.js');
|
|---|
| 7 |
|
|---|
| 8 | function 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 |
|
|---|
| 37 | exports.pullAllWith = pullAllWith;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.