News for hackers. Stuff that matters.
Re:Introducing "Functional JavaScript" by cdumler on Wednesday March 20, 2013 @11:29AM (#5407821)
Functional purity would be nice, but TCO not strictly necessary to be program very functionally. For instance, here TCO would be necessary to prevent the stack from being over-run:

  function fact(x) {
      return (function factIter(i, total){
          if(i<=1){ return total; }
          return factIter(i-1, total*i);
      })(x,1);
  }
However, if you're willing to allow mutation in non-accessible code or closures, there are options:

  function fact(x) {
      if(i<=1) { return 1; }
      return _.range(1,x+1).reduce(
        function(sum, x) { return sum*x; }
      );
  }

There are no comments on this comment yet.