$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #240

Which fix removes the bug?

const ids = new Array(3).map((_, i) => i);
console.log(ids); // expected [0, 1, 2]
  1. Use Array.of(3).map(...)
  2. Call .flat() before .map()
  3. Call .sort() before the .map()
  4. Fill it first: .fill(0).map(...)
new Array(3) has empty slots, and map skips holes; filling the array gives map real elements to visit.
Play Problem Solving ▸