example of function in Trampolines in JavaScript doesn't work #51

Open
cachaito opened this Issue Jul 7, 2015 · 0 comments

Projects

None yet

1 participant

@cachaito
cachaito commented Jul 7, 2015

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 cachaito changed the title from example of function in Trampolines in JavaScript doesn't work to example of function in Trampolines inside JavaScript doesn't work Jul 7, 2015
@cachaito cachaito changed the title from example of function in Trampolines inside JavaScript doesn't work to example of function in Trampolines in JavaScript doesn't work Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment