SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 43 JavaScript
2016-01-28 01:16:24 -08:00
define(['./_baseSlice', './_isIterateeCall', './toInteger'], function(baseSlice, isIterateeCall, toInteger) {
2015-12-16 17:53:20 -08:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
2015-01-08 00:37:01 -08:00
/**
* Creates a slice of `array` from `start` up to, but not including, `end`.
*
2016-03-26 00:00:01 -07:00
* **Note:** This method is used instead of
* [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
* returned.
2015-01-08 00:37:01 -08:00
*
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 3.0.0
2015-01-08 00:37:01 -08:00
* @category Array
* @param {Array} array The array to slice.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`.
*/
function slice(array, start, end) {
2016-10-30 20:06:57 -07:00
var length = array == null ? 0 : array.length;
2015-01-08 00:37:01 -08:00
if (!length) {
return [];
}
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
start = 0;
end = length;
}
2015-12-16 17:53:20 -08:00
else {
start = start == null ? 0 : toInteger(start);
end = end === undefined ? length : toInteger(end);
}
2015-01-08 00:37:01 -08:00
return baseSlice(array, start, end);
}
return slice;
});