Last active
April 9, 2018 13:26
-
-
Save Gergling/f23c139c35cdc84133fed3c2f3fd068c to your computer and use it in GitHub Desktop.
Putting the FUN in FUNctional programming.
This file contains hidden or 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
// Takes a function with two parameters and allows them to be used in the format fnc(x)(y)(). | |
function functionalise(fnc) { | |
return function functionalised(x) { | |
return function (y) { | |
if (y === undefined) { | |
return x; | |
} else { | |
return functionalised(fnc(x, y)); | |
} | |
}; | |
} | |
} | |
console.log(functionalise((x, y) => x * y)(2)(3)()); | |
console.log(functionalise((x, y) => x + y)(2)(3)()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment