Skip to content

Instantly share code, notes, and snippets.

@naush
Created June 20, 2010 15:45
Show Gist options
  • Save naush/445915 to your computer and use it in GitHub Desktop.
Save naush/445915 to your computer and use it in GitHub Desktop.
function fib_recursive(n) {
if (n <= 1)
return n;
return fib_recursive(n - 1) + fib_recursive(n - 2);
}
var fib = new Object();
fib.recursive = function(n) {
if (n <= 1)
return n;
return this.recursive(n - 1) + this.recursive(n - 2);
}
fib.iterative = function(n) {
var a = 0;
var b = 1;
var c = 0;
for (i = 0; i < n; i++) {
c = a + b;
a = b;
b = c;
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment