Created
February 23, 2017 07:39
-
-
Save fuchao2012/ecc8495b3bf555b6d93536abd3a05b5e to your computer and use it in GitHub Desktop.
fib-generator tags: #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
function* fib(){ | |
let a=1, b=1 | |
yield a | |
yield b | |
while(true){ | |
let next = a+b | |
a=b | |
b=next | |
yield next | |
} | |
} | |
let gener = fib() | |
for(let i of Array(10).keys()){ | |
console.log(gener.next().value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment