Skip to content

Instantly share code, notes, and snippets.

@roden0
Created May 28, 2018 20:06
Show Gist options
  • Save roden0/cc9cdc5c45a2116e905242962f30d206 to your computer and use it in GitHub Desktop.
Save roden0/cc9cdc5c45a2116e905242962f30d206 to your computer and use it in GitHub Desktop.
fibonacci generator
function* fibonacci() { // una función generador
let [prev, curr] = [0, 1];
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
for (let n of fibonacci()) {
console.log(n);
// interrumpir la secuencia en 1000
if (n >= 100) {
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment