RosettaCodeData/Task/Y-combinator/JavaScript/y-combinator-4.js
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

13 lines
259 B
JavaScript

function pseudoY(f) {
return function g() {
return f.apply(g, arguments);
};
}
var fac = pseudoY(function(n) {
return n > 1 ? n * this(n - 1) : 1;
});
var fib = pseudoY(function(n) {
return n > 1 ? this(n - 1) + this(n - 2) : n;
});