source: node_modules/es-toolkit/dist/array/remove.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: 522 bytes
Line 
1function remove(arr, shouldRemoveElement) {
2 const originalArr = arr.slice();
3 const removed = [];
4 let resultIndex = 0;
5 for (let i = 0; i < arr.length; i++) {
6 if (shouldRemoveElement(arr[i], i, originalArr)) {
7 removed.push(arr[i]);
8 continue;
9 }
10 if (!Object.hasOwn(arr, i)) {
11 delete arr[resultIndex++];
12 continue;
13 }
14 arr[resultIndex++] = arr[i];
15 }
16 arr.length = resultIndex;
17 return removed;
18}
19
20export { remove };
Note: See TracBrowser for help on using the repository browser.