Skip to content

Instantly share code, notes, and snippets.

@ryohji
Created September 12, 2019 15:46
Show Gist options
  • Save ryohji/036ebe410fdf46f9cfa5cdc6441ad199 to your computer and use it in GitHub Desktop.
Save ryohji/036ebe410fdf46f9cfa5cdc6441ad199 to your computer and use it in GitHub Desktop.
Z combinator
const Z = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y)));
const fact = Z(f => x => x != 0 ? x * f(x-1) : 1);
fact(5); // => 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment