Created
May 6, 2015 11:16
-
-
Save vinzdef/635d07712d9a2e8c8828 to your computer and use it in GitHub Desktop.
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 fact (num){ | |
this.cache = {} | |
//IF KEY NOT SET | |
if (!this.cache.hasOwnProperty(num)){ | |
//COMPUTE AND MEMORIZE | |
fact.cache[num] = num <= 1 ? 1 : num * fact(num-1); | |
} | |
return fact.cache[num]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment