Created
May 29, 2015 20:24
-
-
Save sergiodxa/8a3c086aaac6414e3cf2 to your computer and use it in GitHub Desktop.
Ejemplo de un ES6 Generator
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* fizzBuzz () { | |
let i = 0; | |
while (i <= 100) { | |
i++; | |
let response = ''; | |
if (i % 3 === 0) response += 'Fizz'; | |
if (i % 5 === 0) response += 'Buzz'; | |
if (response === '') yield i; | |
else yield response; | |
} | |
} | |
for (let numero of fizzBuzz()) { | |
console.log(numero); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment