source: node_modules/es-toolkit/dist/array/remove.js

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

Added visualizations

  • Property mode set to 100644
File size: 617 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function remove(arr, shouldRemoveElement) {
6 const originalArr = arr.slice();
7 const removed = [];
8 let resultIndex = 0;
9 for (let i = 0; i < arr.length; i++) {
10 if (shouldRemoveElement(arr[i], i, originalArr)) {
11 removed.push(arr[i]);
12 continue;
13 }
14 if (!Object.hasOwn(arr, i)) {
15 delete arr[resultIndex++];
16 continue;
17 }
18 arr[resultIndex++] = arr[i];
19 }
20 arr.length = resultIndex;
21 return removed;
22}
23
24exports.remove = remove;
Note: See TracBrowser for help on using the repository browser.