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

Which fix removes the bug?

function debounce(fn, ms) {
  let t;
  return function (...args) {
    clearTimeout(t);
    t = setTimeout(fn(...args), ms);
  };
}
  1. Remove clearTimeout(t) from the body
  2. Change to setTimeout(() => fn(...args), ms)
  3. Change let t to const t in the closure
  4. Move clearTimeout after setTimeout
fn(...args) runs immediately; pass a function instead.
Play Problem Solving ▸