Skip to content

Instantly share code, notes, and snippets.

@psynewave
Created February 1, 2021 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psynewave/a4736b2d322da092c7aa61498330f2f6 to your computer and use it in GitHub Desktop.
Save psynewave/a4736b2d322da092c7aa61498330f2f6 to your computer and use it in GitHub Desktop.
const take = (arr, n = 1, fromStart = true) => fromStart ? arr.slice(0, n) : n < 0 ? arr.slice(n) : arr.slice(-1 * n);
let fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
take(fruits)
take(fruits, 3)
take(fruits, -3, false)
take(fruits, 3, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment