Created
June 15, 2012 03:29
-
-
Save learning/2934515 to your computer and use it in GitHub Desktop.
memfactorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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