blob: 15cdb7773b3b1dce19140c332bd2a846114a61b0 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
2 * array-slice <https://github.com/jonschlinkert/array-slice>
3 *
4 * Copyright (c) 2014-2017, Jon Schlinkert.
5 * Released under the MIT License.
6 */
7
8'use strict';
9
10module.exports = function slice(arr, start, end) {
11 var len = arr.length;
12 var range = [];
13
14 start = idx(len, start);
15 end = idx(len, end, len);
16
17 while (start < end) {
18 range.push(arr[start++]);
19 }
20 return range;
21};
22
23function idx(len, pos, end) {
24 if (pos == null) {
25 pos = end || 0;
26 } else if (pos < 0) {
27 pos = Math.max(len + pos, 0);
28 } else {
29 pos = Math.min(pos, len);
30 }
31
32 return pos;
33}