Created
May 27, 2018 02:26
-
-
Save sethdavis512/737b113349ce41a329c5394af7517624 to your computer and use it in GitHub Desktop.
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 increment(input) { return input + 1;} | |
function decrement(input) { return input - 1; } | |
function double(input) { return input * 2; } | |
function halve(input) { return input / 2; } | |
var initial_value = 1; | |
var pipeline = [ | |
increment, | |
increment, | |
increment, | |
double, | |
increment, | |
increment, | |
halve | |
]; | |
var final_value = pipeline.reduce(function(acc, fn) { | |
return fn(acc); | |
}, initial_value); | |
var reversed = pipeline.reduceRight(function(acc, fn) { | |
return fn(acc); | |
}, initial_value) | |
console.log("final_value: ", final_value) | |
console.log("reversed: ", reversed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment