Posterous theme by Cory Watilo

Filed under: combinator

The Y Combinator (Crockford)

See Crockford’s article.

Head over to remy sharp’s JS Bin and play.

var Y = function (le) {
  return ((function (f) {
    return f(f);
  })(function (f) {
    return le(function (x) {
      return f(f)(x);
    });
  }));
};

var factorial = Y(function (fac) {
  return function (n) {
    return (n <= 2) ? n : n * fac(n - 1);
  };
});

!!(factorial(5) === 120); //true