Last active
November 14, 2022 12:47
-
-
Save jonurry/eb294c4cbe0df5377f11922bdbe727bb to your computer and use it in GitHub Desktop.
5.2 Your own loop (Eloquent JavaScript Solutions)
This file contains hidden or 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
// 5.2 looping version | |
function loop(value, test, update, body) { | |
for (let i = value; test(i); i = update(i)) { | |
body(i) | |
} | |
} | |
loop(3, n => n > 0, n => n - 1, console.log); | |
// β 3 | |
// β 2 | |
// β 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, @commodore7 and @Dhaneyl
I obviously never tested that... π