medium+250 XPEnded 3 Aug
Write debounce from scratch
A debounced function waits until the calls stop coming before it actually runs. Type ten characters quickly and the search fires once, not ten times.
Implement debounce(fn, wait) returning a new function that delays calling fn until wait milliseconds have passed without another call.
What it has to do
- Reset the timer every time the debounced function is called again.
- Call
fnwith the arguments from the most recent call. - Preserve
thiswhen the debounced function is used as a method. - Expose a
.cancel()that stops a pending call.
Your workspace
Try it yourself· Edit the code, then press Run
Loading playground...
Ready to check it?
5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
Stuck? The javascript course covers everything this challenge needs.