Last active
July 28, 2016 20:29
-
-
Save jafow/3f840ce2381810025edb8d0c5c94a8b3 to your computer and use it in GitHub Desktop.
Combo
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
/** Write a function `combo` that takes two parameters--fn1, fn2--and returns a function. | |
* combo should combine the two function parameters and invoke them on any values passed as arguments | |
* ex: | |
* var add2 = (n) => n + 2; | |
* var times3 = (n) => n * 3; | |
* var plus2AndMultiply3 = combo(add2, times/3) | |
* plus2AndMulitply3(5) // --> 17 | |
*/ | |
// Function composition in Es6 | |
const combo = (fn1, fn2) => (...args) => fn1(fn2(args)); | |
// ES5 | |
function combo (fn1, fn2) { | |
return function () { | |
var args = Array.prototype.slice.call(arguments); | |
return fn1(fn2(args)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment