Skip to content

Instantly share code, notes, and snippets.

@adambom
Created June 29, 2012 20:54
Show Gist options
  • Save adambom/3020587 to your computer and use it in GitHub Desktop.
Save adambom/3020587 to your computer and use it in GitHub Desktop.
How to do factorial
function factorial(n) {
return n < 2 ? 1 : n * factorial(n - 1);
};
var fastFac = (function () {
var memo = {};
return function (n) {
if (memo[n]) {
return memo[n];
}
memo[n] = factorial(n);
return memo[n];
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment