Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 1.66 KB

File metadata and controls

16 lines (12 loc) · 1.66 KB

Take Elements hard #array

by Eirik Måseidvåg @Eirmas

Take the Challenge

Implement a type Take<N, Arr> that returns the first N elements from an array Arr. If N is negative, return the last |N| elements

For example,

type T0 = Take<2, [1, 2, 3]> // [1, 2]
type T1 = Take<3, ['1', 2, true, false]> // ['1', 2, true]
type T2 = Take<-2, [1, 2, 3]> // [2, 3]
type T3 = Take<0, [1, 2, 3]> // []
type T4 = Take<5, [1, 2, 3]> // [1, 2, 3]
type T5 = Take<3, []> // []

Back Share your Solutions Check out Solutions

Related Challenges

216・Slice