Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created May 27, 2018 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sethdavis512/737b113349ce41a329c5394af7517624 to your computer and use it in GitHub Desktop.
Save sethdavis512/737b113349ce41a329c5394af7517624 to your computer and use it in GitHub Desktop.
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