source: node_modules/es-toolkit/dist/compat/array/slice.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: 1014 bytes
RevLine 
[a762898]1import { isIterateeCall } from '../_internal/isIterateeCall.mjs';
2import { isArrayLike } from '../predicate/isArrayLike.mjs';
3import { toInteger } from '../util/toInteger.mjs';
4
5function slice(array, start, end) {
6 if (!isArrayLike(array)) {
7 return [];
8 }
9 const length = array.length;
10 if (end === undefined) {
11 end = length;
12 }
13 else if (typeof end !== 'number' && isIterateeCall(array, start, end)) {
14 start = 0;
15 end = length;
16 }
17 start = toInteger(start);
18 end = toInteger(end);
19 if (start < 0) {
20 start = Math.max(length + start, 0);
21 }
22 else {
23 start = Math.min(start, length);
24 }
25 if (end < 0) {
26 end = Math.max(length + end, 0);
27 }
28 else {
29 end = Math.min(end, length);
30 }
31 const resultLength = Math.max(end - start, 0);
32 const result = new Array(resultLength);
33 for (let i = 0; i < resultLength; ++i) {
34 result[i] = array[start + i];
35 }
36 return result;
37}
38
39export { slice };
Note: See TracBrowser for help on using the repository browser.