Created
June 29, 2012 20:54
-
-
Save adambom/3020587 to your computer and use it in GitHub Desktop.
How to do factorial
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 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