Skip to content

Instantly share code, notes, and snippets.

@beije
Last active August 29, 2015 14:21
Show Gist options
  • Save beije/224cfb66c327f3e36f54 to your computer and use it in GitHub Desktop.
Save beije/224cfb66c327f3e36f54 to your computer and use it in GitHub Desktop.
Fibonacci with ES6 generators
function *fibonacci(numbers) {
var prevValue = 0;
var currentValue = 1;
var newValue = 0;
for(var i = 0; i < numbers; i++) {
newValue = currentValue+prevValue;
prevValue = currentValue;
currentValue = newValue;
yield currentValue;
}
}
for (var v of fibonacci(10)) {
console.log( v );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment