Created
March 27, 2016 10:58
-
-
Save ebsbk/880564e4fb24f41fca98 to your computer and use it in GitHub Desktop.
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 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