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

Which fix removes the bug?

const results = [];
items.forEach(async (i) => {
  results.push(await load(i));
});
console.log(results.length);
  1. Use a for...of loop
  2. Await inside forEach
  3. Return from the callback
  4. Wrap in Promise.race
forEach ignores the returned promises, so the log runs before anything resolves.
Play Problem Solving ▸