Skip to content

Instantly share code, notes, and snippets.

@lucian303
Created March 8, 2015 22:46
Show Gist options
  • Save lucian303/5573d1f7d407b15e838a to your computer and use it in GitHub Desktop.
Save lucian303/5573d1f7d407b15e838a to your computer and use it in GitHub Desktop.
fibonacci
// Fibonacci
// Loop
var first = 0,
second = 1,
total = 0;
for (var x = 1; x <= 8; x++) {
first = second;
second = total;
total = first + second;
}
alert(total);
// Recursive
function fib(n) {
if (n < 2) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
alert(fib(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment