Implement Promise.race
MediumImplement promiseRace(promises) function that works like native Promise.race().
Requirements:
- Takes an array of promises
- Resolves/rejects with the result of the first settled promise
- Other promises are ignored (but continue executing)
- Empty array should return a promise that never resolves
- Must handle both fulfilled and rejected promises
- DO NOT use built-in Promise.race()
Example:
const result = await promiseRace([
new Promise(res => setTimeout(() => res('slow'), 100)),
new Promise(res => setTimeout(() => res('fast'), 50))
]);
// result = 'fast' (first to complete)JavaScript•UTF-8
Run your code to see results.
Click the Run button above
Mobile view - please use desktop for better experience