UNPKG

1.03 kBJavaScriptView Raw
1var baseSlice = require('./_baseSlice'),
2 isIterateeCall = require('./_isIterateeCall'),
3 toInteger = require('./toInteger');
4
5/**
6 * Creates a slice of `array` from `start` up to, but not including, `end`.
7 *
8 * **Note:** This method is used instead of
9 * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
10 * returned.
11 *
12 * @static
13 * @memberOf _
14 * @since 3.0.0
15 * @category Array
16 * @param {Array} array The array to slice.
17 * @param {number} [start=0] The start position.
18 * @param {number} [end=array.length] The end position.
19 * @returns {Array} Returns the slice of `array`.
20 */
21function slice(array, start, end) {
22 var length = array == null ? 0 : array.length;
23 if (!length) {
24 return [];
25 }
26 if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
27 start = 0;
28 end = length;
29 }
30 else {
31 start = start == null ? 0 : toInteger(start);
32 end = end === undefined ? length : toInteger(end);
33 }
34 return baseSlice(array, start, end);
35}
36
37module.exports = slice;