const debounce = (fn, delay) => {
let timer;
return function () {
clearTimeout(timer);
timer = setTimeout(fn, delay);
};
};
// Example
let count = 0;
const increaseCount = (num) => {
count += num;
console.log(count);
};
window.addEventListener('scroll', debounce(increaseCount.bind(null, 5), 200));