Which fix removes the bug?
const ids = new Array(3).map((_, i) => i); console.log(ids); // expected [0, 1, 2]
- Use
Array.of(3).map(...) - Call
.flat()before.map() - Call
.sort()before the.map() - 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 ▸