Created
July 9, 2014 21:25
-
-
Save amacdougall/f6151270c3c50bbb25e9 to your computer and use it in GitHub Desktop.
That one pipeline question
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
// Make a function called pipeline that accepts a value as a parameter, as well as any number of functions as additional parameters. | |
// The function will return the value that results from the first parameter being used as a parameter for the next function and so on. | |
var double = function(val) { return val * 2; } | |
var addOne = function(val) { return val + 1; } | |
var addThree = function(val) { return val + 3; } | |
/** | |
* Given an initial value and any number of function arguments, | |
* returns the value obtained by applying each function to the | |
* result of the previous one. | |
*/ | |
function pipeline() { | |
// implementation | |
} | |
console.log(pipeline(5, double)) // should return 10 | |
console.log(pipeline(5, double, addOne)) // should return 11 | |
console.log(pipeline(3, addThree, double, addOne)) // should return 13 | |
console.log(pipeline(0, addOne, addOne, addOne, addOne, addOne)) // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment