all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
18
Task/Y-combinator/JavaScript/y-combinator-1.js
Normal file
18
Task/Y-combinator/JavaScript/y-combinator-1.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function Y(f) {
|
||||
var g = f(function() {
|
||||
return g.apply(this, arguments);
|
||||
});
|
||||
return g;
|
||||
}
|
||||
|
||||
var fac = Y(function(f) {
|
||||
return function(n) {
|
||||
return n > 1 ? n * f(n - 1) : 1;
|
||||
};
|
||||
});
|
||||
|
||||
var fib = Y(function(f) {
|
||||
return function(n) {
|
||||
return n > 1 ? f(n - 1) + f(n - 2) : n;
|
||||
};
|
||||
});
|
||||
14
Task/Y-combinator/JavaScript/y-combinator-2.js
Normal file
14
Task/Y-combinator/JavaScript/y-combinator-2.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function Y(f) {
|
||||
var g = f((function(h) {
|
||||
return function() {
|
||||
var g = f(h(h));
|
||||
return g.apply(this, arguments);
|
||||
}
|
||||
})(function(h) {
|
||||
return function() {
|
||||
var g = f(h(h));
|
||||
return g.apply(this, arguments);
|
||||
}
|
||||
}));
|
||||
return g;
|
||||
}
|
||||
9
Task/Y-combinator/JavaScript/y-combinator-3.js
Normal file
9
Task/Y-combinator/JavaScript/y-combinator-3.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function Y(f) {
|
||||
return (function(h) {
|
||||
return h(h);
|
||||
})(function(h) {
|
||||
return f(function() {
|
||||
return h(h).apply(this, arguments);
|
||||
});
|
||||
});
|
||||
}
|
||||
13
Task/Y-combinator/JavaScript/y-combinator-4.js
Normal file
13
Task/Y-combinator/JavaScript/y-combinator-4.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
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;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue