Skip to content

Instantly share code, notes, and snippets.

@dlwjiang
Last active August 5, 2018 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlwjiang/ff27e5638ef846e663e5d190c6a851f7 to your computer and use it in GitHub Desktop.
Save dlwjiang/ff27e5638ef846e663e5d190c6a851f7 to your computer and use it in GitHub Desktop.
expanded y-combinator factorial
// 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