Write Your Own Promise.all
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write promiseAll(items) without using Promise.all, Promise.allSettled, Promise.race or Promise.any. items is an array of promises and plain values, and a plain value counts as already resolved. Return a promise that resolves, once every item has resolved, with an array of their values in the same order as items, whatever order they finished in. An empty array resolves to an empty array straight away. As soon as any item rejects, reject with its reason, without waiting for the rest.
Your code must pass
- Resolves with every value, in input order
- Accepts plain values alongside promises
- Resolves an empty array to an empty array
- Rejects with the first rejection, without waiting
- Works without the built-in Promise combinators