Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 12, 2018 16:19
Show Gist options
  • Save andrit/e7331a2f06d0f74033d66af8558d8f76 to your computer and use it in GitHub Desktop.
Save andrit/e7331a2f06d0f74033d66af8558d8f76 to your computer and use it in GitHub Desktop.
const pipe = functions => data => {
  return functions.reduce(
    (value, func) => func(value),
    data
    );
}

let cart = [3.12, 45.15, 11.01];
const addSalesTax = (total, taxRate) => (total * taxRate) + total;

const tally = orders => pipe([
  x => x.redux((total, val) => total + val), //sum the order
  x => addSalesTax(x, 0.09),
  x => `Order Total = ${x.toFixed(2)}` //convert to text
])(orders);  //Order Total = 64.62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment