1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function slice(array, start, end) { let length = array == null ? 0 : array.length; if (!length) { return []; } start = start == null ? 0 : start; end = end === undefined ? length : end;
if (start < 0) { start = -start > length ? 0 : length + start; } end = end > length ? length : end; if (end < 0) { end += length; } length = start > end ? 0 : (end - start) >>> 0; start >>>= 0;
let index = -1; const result = new Array(length); while (++index < length) { result[index] = array[index + start]; } return result; }
|