first.js 421 B

1234567891011
  1. var initial = require('./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. 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. }
  9. module.exports = first;