source: node_modules/es-toolkit/dist/compat/array/pullAt.js@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const flattenDepth = require('./flattenDepth.js');
6const isIndex = require('../_internal/isIndex.js');
7const isKey = require('../_internal/isKey.js');
8const toKey = require('../_internal/toKey.js');
9const at = require('../object/at.js');
10const unset = require('../object/unset.js');
11const isArray = require('../predicate/isArray.js');
12const toPath = require('../util/toPath.js');
13
14function pullAt(array, ..._indices) {
15 const indices = flattenDepth.flattenDepth(_indices, 1);
16 if (!array) {
17 return Array(indices.length);
18 }
19 const result = at.at(array, indices);
20 const indicesToPull = indices
21 .map(index => (isIndex.isIndex(index, array.length) ? Number(index) : index))
22 .sort((a, b) => b - a);
23 for (const index of new Set(indicesToPull)) {
24 if (isIndex.isIndex(index, array.length)) {
25 Array.prototype.splice.call(array, index, 1);
26 continue;
27 }
28 if (isKey.isKey(index, array)) {
29 delete array[toKey.toKey(index)];
30 continue;
31 }
32 const path = isArray.isArray(index) ? index : toPath.toPath(index);
33 unset.unset(array, path);
34 }
35 return result;
36}
37
38exports.pullAt = pullAt;
Note: See TracBrowser for help on using the repository browser.