Skip to content

Instantly share code, notes, and snippets.

@learning
Created June 15, 2012 03:29
Show Gist options
  • Save learning/2934515 to your computer and use it in GitHub Desktop.
Save learning/2934515 to your computer and use it in GitHub Desktop.
memfactorial
function memfactorial(n){
if(!memfactorial.cache){
memfactorial.cache = {
'0': 1,
'1': 1
};
}
if(!memfactorial.cache.hasOwnProperty(n)){
memfactorial.cache[n] = n * memfactorial(n-1);
}
return memfactorial.cache[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment