-
-
Save azder/10004837 to your computer and use it in GitHub Desktop.
y combinator and the calculation of factorial(5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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