Created
September 25, 2014 03:36
-
-
Save ryancole/71fed8edc2610d53e351 to your computer and use it in GitHub Desktop.
Revisions
-
ryancole created this gist
Sep 25, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ function factorial (n) { return n <= 1 ? 1 : n * factorial(n - 1); }; var factorial_memo = (function () { var memo = [1]; function fac (n) { var result = memo[n]; if (typeof result !== 'number') { result = n * fac(n - 1); memo[n] = result; } return result; }; return fac; }()); for (var i = 0; i <= 40; i += 1) { console.log('// ' + i + ': ' + factorial(i)); } for (var i = 0; i <= 40; i += 1) { console.log('// ' + i + ': ' + factorial_memo(i)); }