Created
March 19, 2014 07:30
-
-
Save avoronkin/9637027 to your computer and use it in GitHub Desktop.
tail recursion with throw ...
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) { | |
function recur(n, result) { | |
if (n == 0) { | |
throw result; | |
} else { | |
recur(n-1, result*n); | |
} | |
} | |
try { | |
recur(n, n); | |
} catch(e) { | |
return e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment