Skip to content

Instantly share code, notes, and snippets.

@sderosiaux
sderosiaux / factorial.js
Created September 23, 2015 11:36
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