function debounce(callback, delay = 300) { let timeoutId; return function debounced(...args) { clearTimeout(timeoutId); timeoutId = setTimeout(() => { callback.apply(this, args); }, delay); }; }