Skip to content

Instantly share code, notes, and snippets.

@ebsbk
Created March 27, 2016 10:58
Show Gist options
  • Save ebsbk/880564e4fb24f41fca98 to your computer and use it in GitHub Desktop.
Save ebsbk/880564e4fb24f41fca98 to your computer and use it in GitHub Desktop.
var factorial = function(self) {
return function(x) {
if(x < 1){
return 1;
}else{
return x * self(x - 1);
}
}
};
var yc = function(rfn) {
return function(x) {
var o = function(y) {
var result = rfn(o)(y);
if (result == NaN) {
return rfn(rfn(o));
}else{
return result;
}
};
return rfn(o)(x);
}
};
yc(factorial)(5);
// 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment