Skip to content

Instantly share code, notes, and snippets.

@vinzdef
Created May 6, 2015 11:16
Show Gist options
  • Save vinzdef/635d07712d9a2e8c8828 to your computer and use it in GitHub Desktop.
Save vinzdef/635d07712d9a2e8c8828 to your computer and use it in GitHub Desktop.
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