Created
February 1, 2021 17:50
-
-
Save psynewave/a4736b2d322da092c7aa61498330f2f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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