7. Implement Promise.all — Frontend Interview Question

medium

Reimplementing Promise.all is the canonical async question. It checks that you understand ordering, the empty case, and that inputs aren't always promises.

The three things that catch people

  1. Order by index, not completion — store results[i], never results.push.
  2. The empty array resolves immediately with [].
  3. Non-promise values — wrap every input in Promise.resolve.

Follow-ups

  • "Now write Promise.allSettled." → never reject; store { status, value | reason } for each.
  • "Promise.race?" → resolve/reject with whichever settles first; no counting.
  • "Promise.any?" → resolve on first fulfilment, reject only if all reject (AggregateError).

What to practice

Implement all, then allSettled and race — they're frequently asked together.

More questions

index.js
function promiseAll(promises) {
  // your code here
}

promiseAll([Promise.resolve(1), 2, Promise.resolve(3)])
  .then((r) => console.log(r)); // [1, 2, 3]

Tests

Test Code

Enter JavaScript that runs after your solution. It should return a value or a Promise.