Sleep
EasyP2Coding
Implement wait(ms), a promise-based delay. It returns a promise that resolves with undefined after at least ms milliseconds and never rejects.
(This is the classic "sleep" helper; it is called wait here because the test environment already provides a sleep function.)
wait(0) still resolves asynchronously: code after the call runs before the promise settles.
Example 1
- Input
- await wait(100); log('done');
- Output
- 'done' is logged about 100 ms later
Constraints
- 0 <= ms <= 10^4
- Use setTimeout.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 6. ⌘Enter runs, ⌘⇧Enter submits.