Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function* fibGenerator() {
- yield 0
- yield 1
- let [ prev, curr ] = [ 0, 1 ]
- while (true) {
- [ prev, curr ] = [ curr, prev + curr ]
- yield curr
- }
- }
- function fibIterator(n) {
- let count = 0
- let fibGen = fibGenerator()
- let result = []
- for (fibNum of fibGen) {
- result.push(fibNum)
- count ++
- if (count >= n) {
- break
- }
- }
- return result
- }
- console.log(fibIterator(10))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement