JavaScript interview: Implement Promise.all

medium
promises
async

Write promiseAll(items) without using Promise.all. It returns a promise that resolves to an array of results in the same order as the input, even if later items finish first.

Plain values count as already resolved. If any item rejects, reject with that reason straight away. An empty array resolves to [].

Your code

Runs in a Web Worker in your browser. Tests use real timers, so a run takes a second or two.

FAQ