Created
June 26, 2012 02:58
-
-
Save fillano/2992993 to your computer and use it in GitHub Desktop.
trampoline sample
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 characters
function factorial(n, a) { | |
a = a||1; | |
if(n===0) { | |
return a; | |
} | |
return function() { | |
return factorial(n-1, a*n); | |
} | |
} | |
function trampoline(c, p) { | |
var r = c(p); | |
while(typeof r === 'function') { | |
r = r(); | |
} | |
return r; | |
} | |
console.log(trampoline(factorial, 100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment