Fill in the blank
// returns a copy of the first 2 elements
function firstTwo<T>(arr: T[]): T[] {
return arr.____(0, 2);
}
// firstTwo([1,2,3,4]) -> [1,2]
Answer: slice
slice(0, 2) returns a non-mutating copy of indices 0 and 1.
Play Problem Solving ▸