Skip to content

Instantly share code, notes, and snippets.

@avoronkin
Created March 19, 2014 07:30
Show Gist options
  • Save avoronkin/9637027 to your computer and use it in GitHub Desktop.
Save avoronkin/9637027 to your computer and use it in GitHub Desktop.
tail recursion with throw ...
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