MediumPro challengePythonJavaScriptTypeScript

Implement Promise.race

AsyncPromises

Implement promiseRace(promises) — return a promise that resolves or rejects
with the first promise that settles.

solve(delays, shouldReject) simulates a race: each entry is a [delayMs, value]
pair. If the corresponding shouldReject flag is true the promise rejects
with value instead.

Constraint: Do NOT use Promise.race itself.

Sample tests

Test #1Single promise
Input: [[[10,"win"]],[false]]
Output: {"value":"win","status":"resolved"}
Test #2Fastest resolves first
Input: [[[10,"fast"],[50,"slow"]],[false,false]]
Output: {"value":"fast","status":"resolved"}
Test #3Second is faster
Input: [[[50,"slow"],[10,"fast"]],[false,false]]
Output: {"value":"fast","status":"resolved"}
Test #4Fastest rejects → race rejects
Input: [[[10,"err"],[50,"ok"]],[true,false]]
Output: {"value":"err","status":"rejected"}
Test #5Slowest resolves, fastest rejects first
Input: [[[50,"ok"],[10,"err"]],[false,true]]
Output: {"value":"err","status":"rejected"}