Created
October 10, 2014 00:10
-
-
Save greduan/2535cb8397d9b017f116 to your computer and use it in GitHub Desktop.
Y Combinator in JavaScript as shown by Douglas Crockford
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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