Skip to content

Instantly share code, notes, and snippets.

@sergiodxa
Created May 29, 2015 20:24
Show Gist options
  • Save sergiodxa/8a3c086aaac6414e3cf2 to your computer and use it in GitHub Desktop.
Save sergiodxa/8a3c086aaac6414e3cf2 to your computer and use it in GitHub Desktop.
Ejemplo de un ES6 Generator
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