Skip to content

Instantly share code, notes, and snippets.

@coltpini
Last active May 8, 2017 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coltpini/4d3e70bf2436f8529eb76c334ba8905d to your computer and use it in GitHub Desktop.
Save coltpini/4d3e70bf2436f8529eb76c334ba8905d to your computer and use it in GitHub Desktop.
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