Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active October 31, 2024 16:56
Show Gist options
  • 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.1
function setTimesout(function_, repeats = [0]) {
if (typeof(function_) !== "function") {
throw new Error("The first argument must be of type 'function'")
}
if (!Array.isArray(repeats)) {
throw new Error("The second argument must be of type 'object' (array)")
}
repeats = repeats.sort((a, b) => {
return a - b
})
for (let i = 0; i < repeats.length; i++) {
setTimeout(() => {
function_(repeats[i], i)
}, repeats[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment