Last active
October 31, 2024 16:56
-
-
Save luislobo14rap/c767b3371802828ed8a2538877e07d6a to your computer and use it in GitHub Desktop.
setTimesout.js
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
// 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