$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #120

Which fix removes the bug?

function debounce(fn, ms) {
  let t;
  return (...a) => {
    t = setTimeout(fn(...a), ms);
  };
}
  1. Clear then defer: clearTimeout(t) and wrap
  2. Clear then defer: clearInterval(t) and wrap
  3. Return the timer id from the inner arrow
  4. Move let t inside the returned function
fn(...a) runs immediately and nothing cancels the previous timer, so it never debounces.
Play Problem Solving ▸