baseSlice.js 832 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * The base implementation of `_.slice` without an iteratee call guard.
  3. *
  4. * @private
  5. * @param {Array} array The array to slice.
  6. * @param {number} [start=0] The start position.
  7. * @param {number} [end=array.length] The end position.
  8. * @returns {Array} Returns the slice of `array`.
  9. */
  10. function baseSlice(array, start, end) {
  11. var index = -1,
  12. length = array.length;
  13. start = start == null ? 0 : (+start || 0);
  14. if (start < 0) {
  15. start = -start > length ? 0 : (length + start);
  16. }
  17. end = (end === undefined || end > length) ? length : (+end || 0);
  18. if (end < 0) {
  19. end += length;
  20. }
  21. length = start > end ? 0 : ((end - start) >>> 0);
  22. start >>>= 0;
  23. var result = Array(length);
  24. while (++index < length) {
  25. result[index] = array[index + start];
  26. }
  27. return result;
  28. }
  29. module.exports = baseSlice;