raganwald.github.com icon indicating copy to clipboard operation
raganwald.github.com copied to clipboard

example of function in Trampolines in JavaScript doesn't work

Open cachaito opened this issue 9 years ago • 0 comments

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

cachaito avatar Jul 07 '15 10:07 cachaito