Skip to content

Instantly share code, notes, and snippets.

@azder
Created April 6, 2014 11:41
Show Gist options
  • Save azder/10004837 to your computer and use it in GitHub Desktop.
Save azder/10004837 to your computer and use it in GitHub Desktop.
y combinator and the calculation of factorial(5)
// Y combinator
function y(le) {
return (function (f) {
return f(f);
}(
function (g) {
return le(function (x) {
return g(g)(x);
});
})
);
}
// factorial(5)
(y(function (fac) {
return function (n) {
return n <= 2 ? n : n * fac(n - 1);
};
}))(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment