Promise.race Polyfill
EasyP2Coding
Implement promiseRace(promises), a polyfill for Promise.race.
It takes an iterable of values or promises and returns a promise that settles the same way as the first input to settle: it resolves with that value or rejects with that reason. Plain non-promise values count as already settled. If several are already settled, the earliest in input order wins. An empty input gives a promise that stays pending forever.
Do not call Promise.race.
Example 1
- Input
- promiseRace([delay(50, 'slow'), delay(10, 'fast')])
- Output
- resolves with 'fast'
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.