Skip to content

Instantly share code, notes, and snippets.

@sderosiaux
Created September 23, 2015 11:36
Show Gist options
  • Select an option

  • Save sderosiaux/f176097d3593d701163e to your computer and use it in GitHub Desktop.

Select an option

Save sderosiaux/f176097d3593d701163e to your computer and use it in GitHub Desktop.
Factorial using a Y-Combinator function
// 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