Last active
April 17, 2020 05:35
-
-
Save yitonghe00/27359e8d6c6ee5c7996787d04a56cfde to your computer and use it in GitHub Desktop.
Eloquent JavaScript 0502 Your own loop https://eloquentjavascript.net/05_higher_order.html#i_gKQ1S54F4o
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
// Your code here. | |
const loop = (init, test, next, body) => { | |
for (let i = init; test(i); i = next(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