implement Promise.race()
2022年5月1日小于 1 分钟
Promise.race()
implement Question
This problem is similar to 31. implement async helper - race()
, but with Promise.
The Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise. source: MDN
Can you create a race()
which works the same as Promise.race()
?
Code
/**
* @param {Array<Promise>} promises
* @return {Promise}
*/
function race(promises) {
// your code here
}