Skip to content

Instantly share code, notes, and snippets.

@shawndumas
Last active February 21, 2024 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawndumas/947aa3c6a33d34702672 to your computer and use it in GitHub Desktop.
Save shawndumas/947aa3c6a33d34702672 to your computer and use it in GitHub Desktop.
Yield Example (A.K.A Will You Please Stop!?)
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