Loading problem…
Implement a promiseRace function that behaves like the native Promise.race.
The function takes an array of promises (or values) and returns a new Promise that settles as soon as the first input settles (either resolves or rejects).
Promise.resolve.const fast = Promise.resolve('fast');
const slow = new Promise(resolve => setTimeout(() => resolve('slow'), 100));
promiseRace([fast, slow]).then(value => {
console.log(value); // 'fast'
});
const error = Promise.reject('fail');
promiseRace([
error,
new Promise(resolve => setTimeout(() => resolve('slow'), 100))
]).catch(reason => {
console.log(reason); // 'fail'
});