#5 most askedVery commonMediumBuild it yourself
Implement debounce
🏢 Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Write debounce(fn, ms). It returns a function that waits until it hasn't been called for ms milliseconds, then calls fn once with the latest arguments.
Used for search boxes: only search after the user stops typing.
🧪 Practice
Write your solution, then press Run tests. Explain your approach out loud as you go.
function debounce(fn, ms) {
// your code here
}
Output appears here. Press Run or Ctrl/⌘ + Enter.
Try it first. Struggling for a few minutes is how it sticks.