Create promiseRace that settles (resolve or reject) as soon as the first promise settles. Handle empty array (never settles).
Skip to solutionKEEP THE
easyFrontend
Implement Promise.race()
886 views
01
Understand the problem
promisepromiseRace
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Approach: Iterate and attach then(resolve, reject) to outer promise; first settlement wins.
function promiseRace(iterable) {
const promises = [...iterable];
return new Promise((resolve, reject) => {
for (const p of promises) Promise.resolve(p).then(resolve, reject);
});
}
// Demo
promise
Solution ready — 2 min read
Classified // press E to declassify
04
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 42 of 190 decoded in the JavaScript Coding track. One more won't hurt.