medium+250 XPPractice Available
Write debounce from scratch
A debounced function waits until the calls stop coming before it actually runs.
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?
4 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.
Stuck? The javascript course covers everything this challenge needs.