Last active
November 15, 2019 06:10
-
-
Save romasan/d0ff4f32a5246743f0a9478f433c1d88 to your computer and use it in GitHub Desktop.
This file contains 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
const peakBounce = (interval, count) => { | |
let iCount = 0; | |
let stack = []; | |
setInterval(() => { | |
const part = stack.splice(0, count); | |
part.forEach(fn => fn()) | |
iCount = part.length; | |
}, interval); | |
return (fn, ...a) => { | |
if (typeof fn !== 'function') {return} | |
if (iCount < count) { | |
iCount++; | |
fn(...a); | |
} else { | |
stack.push(() => { | |
fn(...a); | |
}) | |
} | |
} | |
} | |
const pb = peakBounce(1000, 2); | |
const f = i => {console.log(i)} | |
pb(f, 1); | |
pb(f, 2); | |
pb(f, 3); | |
pb(f, 4); | |
pb(f, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment