Last active
August 5, 2018 23:50
-
-
Save dlwjiang/ff27e5638ef846e663e5d190c6a851f7 to your computer and use it in GitHub Desktop.
expanded y-combinator factorial
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
// This writes out the same function twice. | |
// If you consider the top function `pseudoFactorial` and the bottom function as `copy` | |
// you can read it as `pseudoFactorial(copy)` | |
// | |
// As pseudoFactorial creates a function that creates a function, | |
// this creates the factorial function, ready to take in `n` | |
const factorial = (f => n => { | |
if (n < 2) return 1; | |
return n * f(f)(n-1); | |
})(f => n => { | |
if (n < 2) return 1; | |
return n * f(f)(n-1); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment