Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active May 11, 2023 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luislobo14rap/c767b3371802828ed8a2538877e07d6a to your computer and use it in GitHub Desktop.
Save luislobo14rap/c767b3371802828ed8a2538877e07d6a to your computer and use it in GitHub Desktop.
setTimesout.js
// setTimesout.js v2
function setTimesout(function_ = (time, index) => {}, repeats = [0]) {
repeats = repeats.sort((a, b) => {
return a - b
})
for (let i = 0; i < repeats.length; i++) {
setTimeout(() => {
function_(time = repeats[i], index = i)
}, repeats[i])
}
}
// setTimesout.min.js v2
function setTimesout(a=function(){},b=[0]){b=b.sort(function(c,a){return c-a});for(let c=0;c<b.length;c++)setTimeout(function(){a(time=b[c],index=c)},b[c])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment