Created
September 23, 2015 11:36
-
-
Save sderosiaux/f176097d3593d701163e to your computer and use it in GitHub Desktop.
Factorial using a Y-Combinator function
This file contains hidden or 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
| // http://anler.me/posts/2015-09-17-recursion-aerobics.html | |
| const Y = f => (g => g(g))(g => (f)(arg => (g(g))(arg))); | |
| // define the fact function | |
| const fact = Y(f => n => n === 0 ? 1 : n * f(n-1)); | |
| fact(5); | |
| // 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment