$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #154

Which fix removes the bug?

const nums = [1, 2, 3];
const doubled = nums.forEach((n) => n * 2);
console.log(doubled);
  1. Use map instead
  2. Add a return statement
  3. Wrap it in Array.from
  4. Declare doubled with let
forEach always returns undefined; map is what collects the results.
Play Problem Solving ▸