$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #209

Which fix removes the bug?

function sum(...nums: number[]): number {
  return nums.reduce((a, b) => a + b, 0);
}
sum([1, 2, 3]);
  1. Type nums as number[][]
  2. Drop the 0 seed in reduce
  3. Return nums.length instead
  4. Spread it: sum(...[1, 2, 3])
A rest parameter collects separate arguments; passing one array gives a type error.
Play Problem Solving ▸