Proof of Work · Challenge
A burst of calls becomes the last one.
about 25 min · 5 required tests · in the browser
What is recorded: when you save, your Result page shows your code, which tests passed, how many times you ran the tests, how many versions you tried, the time from first run to save, and the largest jump in code between runs. Anyone with the link can see it. The suggested time is not enforced.
A search box should not hit the network on every keystroke. Wait until the typing pauses, then send the latest query once.
Implement debounce(fn, wait).
It returns a new function. That function does not call fn immediately. It waits wait milliseconds. If it is called again before the wait ends, the timer starts over and the previous call is discarded. When the wait finally elapses, fn runs once, with the arguments from the most recent call.
With wait of 100:
const d = debounce((q) => search(q), 100)
d("c")
// 40ms pass: search has not run
d("ca")
// 100ms pass with no further calls
// search runs once, with "ca"The grader moves time on a virtual clock. setTimeout, clearTimeout, and Date.now work. Time does not pass on its own, and setInterval is not available.
Requirements:
fn is not called until wait ms elapse with no new calls.fn.fn receives the arguments from the latest call.Write a top-level function named debounce. Do not use export or module.exports.
Optional: a cancel() method on the returned function that drops a pending call. The required tests pass without it.
Try the contract
This is the behavior the tests check. It is not your code.
Wait left
idle
Press Esc, then Tab, to leave the editor.
⌘ / Ctrl + Enter runs the tests
Hiring developers? See how teams use this.
Graded on
0/5
Other builds