Skip to content

Instantly share code, notes, and snippets.

@ambidexterich
Created May 15, 2015 19:57
Show Gist options
  • Save ambidexterich/72197a8bd418a2c3e877 to your computer and use it in GitHub Desktop.
Save ambidexterich/72197a8bd418a2c3e877 to your computer and use it in GitHub Desktop.
Y-Combinator in JS for factorization
var Y = function (F) {
return (function (x) {
return F(function (y) {
return (x(x))(y);
});
})(function (x) {
return F(function (y) {
return (x(x))(y);
});
});
};
var FactGen = function (fact) {
return (function(n) {
return ((n === 0) ? 1 : (n*fact(n-1)));
});
};
console.log((Y(FactGen))(3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment