|
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.1 KB
|
| Rev | Line | |
|---|
| [a762898] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isIterateeCall = require('../_internal/isIterateeCall.js');
|
|---|
| 6 | const isArrayLike = require('../predicate/isArrayLike.js');
|
|---|
| 7 | const toInteger = require('../util/toInteger.js');
|
|---|
| 8 |
|
|---|
| 9 | function slice(array, start, end) {
|
|---|
| 10 | if (!isArrayLike.isArrayLike(array)) {
|
|---|
| 11 | return [];
|
|---|
| 12 | }
|
|---|
| 13 | const length = array.length;
|
|---|
| 14 | if (end === undefined) {
|
|---|
| 15 | end = length;
|
|---|
| 16 | }
|
|---|
| 17 | else if (typeof end !== 'number' && isIterateeCall.isIterateeCall(array, start, end)) {
|
|---|
| 18 | start = 0;
|
|---|
| 19 | end = length;
|
|---|
| 20 | }
|
|---|
| 21 | start = toInteger.toInteger(start);
|
|---|
| 22 | end = toInteger.toInteger(end);
|
|---|
| 23 | if (start < 0) {
|
|---|
| 24 | start = Math.max(length + start, 0);
|
|---|
| 25 | }
|
|---|
| 26 | else {
|
|---|
| 27 | start = Math.min(start, length);
|
|---|
| 28 | }
|
|---|
| 29 | if (end < 0) {
|
|---|
| 30 | end = Math.max(length + end, 0);
|
|---|
| 31 | }
|
|---|
| 32 | else {
|
|---|
| 33 | end = Math.min(end, length);
|
|---|
| 34 | }
|
|---|
| 35 | const resultLength = Math.max(end - start, 0);
|
|---|
| 36 | const result = new Array(resultLength);
|
|---|
| 37 | for (let i = 0; i < resultLength; ++i) {
|
|---|
| 38 | result[i] = array[start + i];
|
|---|
| 39 | }
|
|---|
| 40 | return result;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | exports.slice = slice;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.