Created
January 13, 2015 23:49
-
-
Save doron2402/5ed1564ffb2df1c2983c to your computer and use it in GitHub Desktop.
es6/7 fib
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
function* fib(num) { | |
var prev = 0; | |
var curr = 1; | |
while (curr < num) { | |
var tmp = prev; | |
prev = curr; | |
curr = tmp + curr; | |
yield curr; | |
} | |
} | |
for (var i of fib(10)){ | |
console.log(i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment