Created
May 15, 2015 19:57
-
-
Save ambidexterich/72197a8bd418a2c3e877 to your computer and use it in GitHub Desktop.
Y-Combinator in JS for factorization
This file contains 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
var Y = function (F) { | |
return (function (x) { | |
return F(function (y) { | |
return (x(x))(y); | |
}); | |
})(function (x) { | |
return F(function (y) { | |
return (x(x))(y); | |
}); | |
}); | |
}; | |
var FactGen = function (fact) { | |
return (function(n) { | |
return ((n === 0) ? 1 : (n*fact(n-1))); | |
}); | |
}; | |
console.log((Y(FactGen))(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment