Created
July 27, 2013 14:42
-
-
Save koshuang/6095044 to your computer and use it in GitHub Desktop.
functional basis
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
function addf (x) { | |
return function(y) { | |
return x + y; | |
} | |
} | |
function add (x, y) { | |
return x + y; | |
} | |
function mul (x, y) { | |
return x * y; | |
} | |
function applyf (binary) { | |
return function(x) { | |
return function (y) { | |
return binary(x, y); | |
} | |
} | |
} | |
var addf = applyf(add); | |
console.log(addf(3)(4)); | |
console.log(applyf(mul)(5)(6)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment