Implement Promise.all
Implement promiseAll(iterable), which behaves like Promise.all without calling it. Promise.all, allSettled, race and any are switched off while it runs.
- Resolve with the results in input order, whatever order the promises settle in.
- Accept plain values beside promises, and any iterable, not only arrays.
- Resolve an empty input at once, with
[]. - Reject with the first rejection.
Everything runs on a virtual clock, so the grader sees exactly when the result settles.
Hints
Hint 1
Store each result by index and count down. Pushing results in completion order is the classic bug.
Hint 2
The empty input must resolve immediately, because nothing will ever count down. Wrap each item in Promise.resolve(item) so plain values sit beside promises.
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.