raganwald.github.com
raganwald.github.com copied to clipboard
example of function in Trampolines in JavaScript doesn't work
In this example there is a Uncaught ReferenceError: trampoline is not defined
function factorial (n) {
var _factorial = trampoline( function myself (acc, n) {
return n
? function () { return myself(acc * n, n - 1); }
: acc
});
return _factorial(1, n);
}
factorial(10);
//=> 362800
factorial(32768);
//=> Infinity