Without clearTimeout, every call schedules its own run instead of collapsing into one.
Acceptance criteria
- 1.#out should show 1 ran.
Without clearTimeout, every call schedules its own run instead of collapsing into one.
function debounce(fn, delay) { return function (...args) { setTimeout(function () { fn(...args); }, delay); }; } let calls = 0; const debounced = debounce(function () { calls++; }, 10); debounced(); debounced(); debounced(); setTimeout(function () { document.querySelector('#out').textContent = calls + " ran"; }, 30);
Output ready when you are
Press Run to render your code, or Submit to validate your solution.