Created
December 22, 2020 19:19
-
-
Save jaylandro/17c59b4c64884619b2db0fd29b1d527a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(arr) { | |
return arr.reduce((a,b) => a + b); | |
} | |
function throttle(fn, ms) { | |
let pending = false; | |
return () => { | |
if (!pending) { | |
fn(); | |
pending = true; | |
setTimeout(() => { | |
pending = false; | |
}, ms); | |
} | |
} | |
} | |
const myFunc = () => { | |
console.log("Delayedddd", Date.now()); | |
} | |
let handler = throttle(myFunc, 200); | |
handler() | |
setTimeout(() => handler(), 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment