Promise.allSettled Polyfill
MediumP2Coding
Implement promiseAllSettled(promises), a polyfill for Promise.allSettled.
It takes an iterable of values or promises and returns a promise that never rejects. After every input has settled it resolves with an array, in input order, of result objects:
{ status: 'fulfilled', value }for an input that resolved (plain values count as resolved),{ status: 'rejected', reason }for an input that rejected.
An empty input resolves with []. Do not call Promise.allSettled.
Example 1
- Input
- promiseAllSettled([Promise.resolve(1), Promise.reject('no')])
- Output
- [{ status: 'fulfilled', value: 1 }, { status: 'rejected', reason: 'no' }]
Constraints
- 0 <= number of items <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.