Create sleep that returns a promise resolving after ms milliseconds. Also implement delay(fn, ms) that delays execution.
Skip to solutionKEEP THE
easyFrontend
Implement sleep(ms) and delay with value
115 views
01
Understand the problem
sleepdelaypromise
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: new Promise(resolve => setTimeout(resolve, ms)). For delay, combine with then.
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
function delay(fn, ms, ...args) { return sleep(ms).then(() => fn(...args)); }
// Demo
(async () => {
console.log('start', Da
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 61 of 190 decoded in the JavaScript Coding track. One more won't hurt.