-
-
Save pid/a2ba9362f3c72f1112ad to your computer and use it in GitHub Desktop.
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 | |
// makes the recursion | |
(function(improver) { | |
return (function(gen) { return gen(gen) })( | |
function(gen) { | |
return improver(function(v) { | |
return gen(gen)(v) | |
}) | |
} | |
) | |
})( | |
// this part is the condition for the factorial | |
function(partial) { | |
return function(n) { | |
return n === 0 ? 1 : n * partial(n - 1) | |
} | |
} | |
// pass any number here to get its factorial | |
)(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment