function debounce(fn, time) {
const timer = null;
return function() {
const context = this;
const args = arguments;
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
}, time)
}
}
function throttle(fn, time) {
let isValid = false;
return function() {
const context = this;
const args = arguments;
if (!isValid) {
fn.apply(this, arguments);
isValid = true;
setTimeout(() => {
isValid = false;
}, time)
}
}
}