Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created January 27, 2013 14:10
Show Gist options
  • Select an option

  • Save lyuehh/4648466 to your computer and use it in GitHub Desktop.

Select an option

Save lyuehh/4648466 to your computer and use it in GitHub Desktop.
function fib(n) {
return fib_iter(1, 0, n);
}
function fib_iter(a, b, count) {
if(count === 0) {
return b;
} else {
return fib_iter(a + b, a, count - 1);
}
}
function fib2(n) {
if(n < 1) {
return n;
} else {
return fib2(n-1) + fib2(n-2);
}
}
console.time('1');
console.log(fib2(40)); // 这个为什么是负的....
console.timeEnd('1');
console.time('2');
console.log(fib(40));
console.timeEnd('2');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment