Skip to content

Instantly share code, notes, and snippets.

@NV
Created January 6, 2010 00:43
Show Gist options
  • Select an option

  • Save NV/269902 to your computer and use it in GitHub Desktop.

Select an option

Save NV/269902 to your computer and use it in GitHub Desktop.
Caching fibonacci function
function fib(n) {
if (n==0) {
return 0
} else if (n==1) {
return 1
} else {
return fib[n] = fib[n] || fib(n-2) + fib(n-1)
}
}
console.time('fib')
fib(1000)
console.timeEnd('fib')
// fib: 2ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment