Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2014 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/37c2d470cf08fc9b3846 to your computer and use it in GitHub Desktop.
Save anonymous/37c2d470cf08fc9b3846 to your computer and use it in GitHub Desktop.
fixed fibonacci es6
#!/usr/bin/env node --harmony
'use strict';
var fib = getFibonacci();
init();
function* getFibonacci(){
let val1 = 0, val2 = 1, swap;
yield val1;
yield val2;
while (true){
swap = val1 + val2;
val1 = val2;
val2 = swap;
yield swap;
}
}
function init(){
let i = 0;
while ( i < 10 ) {
console.log(fib.next().value);
i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment