Last active
May 8, 2017 16:53
-
-
Save coltpini/4d3e70bf2436f8529eb76c334ba8905d to your computer and use it in GitHub Desktop.
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 *fibonacci(){ | |
let first = 1; | |
let second = 1; | |
while (true){ | |
let current = second; | |
second = first; | |
first = first + current; | |
yield current; | |
} | |
} | |
let fib = fibonacci(); | |
console.log(fib.next()) // 1 | |
console.log(fib.next()) // 1 | |
console.log(fib.next()) // 2 | |
console.log(fib.next()) // 3 | |
console.log(fib.next()) // 5 | |
console.log(fib.next()) // 8 etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment