javascript snippet
Debounce a function
Throttle rapid calls to run only after the delay.
export function debounce(fn, delay = 200) {let timeout;return (...args) => {clearTimeout(timeout);timeout = setTimeout(() => fn.apply(null, args), delay);};}// Usageconst onResize = debounce(() => console.log("resized"), 150);window.addEventListener("resize", onResize);