const debounce = (func, timeout = 2500) => { if (typeof func !== "function") { console.error(`func must be a valid function, ${typeof func} provided`) return } let timer return (...args) => { clearTimeout(timer) timer = setTimeout(() => { func.apply(this, args) }, timeout) } }