Skip to content

Instantly share code, notes, and snippets.

View kogovsekmatic's full-sized avatar

Matic Kogovšek kogovsekmatic

  • Ljubljana
View GitHub Profile
function throttle(fn, w){
let lock;
let res;
return function(...args){
if(lock){
return res;
}else{
setTimeout(() => lock = false, w);
res = fn.apply(this, args);
function wait(fn, w){
let last = new Date(0);
let res;
return function(...args){
const time = new Date();
if(last.getTime() + w < time.getTime()){
res = fn.apply(this, args);
last = time;