Promise.race
Promise.race
Implement your own version of Promise.race that returns the first settled promise.
Requirements:
- Return a Promise that settles with the first settled promise
- Can either resolve or reject based on the first settled promise
Example:
const p1 = new Promise(resolve => setTimeout(() => resolve('slow'), 500));
const p2 = new Promise(resolve => setTimeout(() => resolve('fast'), 100));
promiseRace([p1, p2]).then(value => {
console.log(value); // 'fast'
});
Examples:
Input 1:
{"value":"fast"}Output 1:
"fast"Loading editor...
Run your code to see results
Click the Run button above