first.js 408 B

12345678910
  1. import initial from './initial.js';
  2. // Get the first element of an array. Passing **n** will return the first N
  3. // values in the array. The **guard** check allows it to work with `_.map`.
  4. export default function first(array, n, guard) {
  5. if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
  6. if (n == null || guard) return array[0];
  7. return initial(array, array.length - n);
  8. }