Skip to content

Instantly share code, notes, and snippets.

@fillano
Created June 26, 2012 02:58
Show Gist options
  • Save fillano/2992993 to your computer and use it in GitHub Desktop.
Save fillano/2992993 to your computer and use it in GitHub Desktop.
trampoline sample
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