Last active
February 21, 2024 11:54
-
-
Save shawndumas/947aa3c6a33d34702672 to your computer and use it in GitHub Desktop.
Yield Example (A.K.A Will You Please Stop!?)
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
function* fromOneTo (max) { | |
var i = 0; | |
while (max--) { | |
yield ++i; | |
} | |
}; | |
for (var i of fromOneTo(100)) { | |
var r = ''; | |
if (i%3 < 1) { r += 'Fizz'; } | |
if (i%5 < 1) { r += 'Buzz'; } | |
if (r === '') { r = i; }; | |
console.log(r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment