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

Which fix removes the bug?

const found = [1, 2, 3].forEach((n) => {
  if (n === 2) return n;
});
  1. Use find so the match is returned
  2. Use filter so the match is returned
  3. Add return before the forEach call
  4. Change the arrow to a normal function
forEach always returns undefined and a return inside it only exits that callback; find returns the match.
Play Problem Solving ▸