Skip to content

Instantly share code, notes, and snippets.

@NameFILIP
Last active August 29, 2015 14:06
Show Gist options
  • Save NameFILIP/60bf51567ee83ffdc343 to your computer and use it in GitHub Desktop.
Save NameFILIP/60bf51567ee83ffdc343 to your computer and use it in GitHub Desktop.
Javascript Y combinator (Crockford)
function y(le) {
return (function (f) {
return f(f);
}(function (f) {
return le(function (x) {
return f(f)(x);
});
}));
}
var factorial = y(function (fac) {
return function (n) {
return n <= 2 ? n : n * fac(n - 1);
};
});
var number120 = factorial(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment