Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created March 20, 2015 18:14
Show Gist options
  • Save wookiecooking/cd9b70246758743ca45f to your computer and use it in GitHub Desktop.
Save wookiecooking/cd9b70246758743ca45f to your computer and use it in GitHub Desktop.
fibonacci
function fibonacci(n) {
let previous = 0;
let current = 1;
for(let i = 0; i < n; i += 1) { // Implicit block scope for the loop header
let temp = previous;
previous = current;
current = temp + current;
}
return current;
}
console.log(fibonacci(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment