Skip to content

Instantly share code, notes, and snippets.

@greduan
Created October 10, 2014 00:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greduan/2535cb8397d9b017f116 to your computer and use it in GitHub Desktop.
Save greduan/2535cb8397d9b017f116 to your computer and use it in GitHub Desktop.
Y Combinator in JavaScript as shown by Douglas Crockford
// playlist:
// http://youtu.be/ya4UHuXNygM?list=PL7664379246A246CB
// minute:
// http://youtu.be/ya4UHuXNygM?t=1h8m42s
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 funcntion (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