$ ./guess_the_languageProblem Solving — fill the blank
Problem Solving — fill the blank · medium · #113

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 (also accepted: slice, slice())

slice(0, 2) returns a non-mutating copy of indices 0 and 1.
Play Problem Solving ▸