initial.js 461B

1234567891011121314151617181920212223
  1. var baseSlice = require('./_baseSlice');
  2. /**
  3. * Gets all but the last element of `array`.
  4. *
  5. * @static
  6. * @memberOf _
  7. * @since 0.1.0
  8. * @category Array
  9. * @param {Array} array The array to query.
  10. * @returns {Array} Returns the slice of `array`.
  11. * @example
  12. *
  13. * _.initial([1, 2, 3]);
  14. * // => [1, 2]
  15. */
  16. function initial(array) {
  17. var length = array == null ? 0 : array.length;
  18. return length ? baseSlice(array, 0, -1) : [];
  19. }
  20. module.exports = initial;