Skip to content

Instantly share code, notes, and snippets.

@jeremiahbiard
Created June 24, 2015 17:40
Show Gist options
  • Save jeremiahbiard/4940d433b5ffd7d65daf to your computer and use it in GitHub Desktop.
Save jeremiahbiard/4940d433b5ffd7d65daf to your computer and use it in GitHub Desktop.
memoized factorial function
var f = [];
function factorial (n) {
if (n == 0 || n == 1)
return 1;
if (f[n] > 0)
return f[n];
return f[n] = factorial(n-1) * n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment