Created
December 16, 2014 11:00
-
-
Save anonymous/37c2d470cf08fc9b3846 to your computer and use it in GitHub Desktop.
fixed fibonacci es6
This file contains 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
#!/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