Skip to content

Instantly share code, notes, and snippets.

@bradurani
Last active September 17, 2015 05:58
Show Gist options
  • Save bradurani/cfe2fb2fcd3b3dd335be to your computer and use it in GitHub Desktop.
Save bradurani/cfe2fb2fcd3b3dd335be to your computer and use it in GitHub Desktop.
Function Factory After
//function injection again
function getTotal(lineItems, taxFunc) {
let subtotal = lineItems.reduce((total, lineItem) => {
return total += lineItem.total
});
return subtotal + taxFunc(subtotal));
}
//function factory
function salesTaxFunc(state) {
switch(state) {
case 'ak': return subTotal => { subTotal };
case 'co': return subTotal => { subTotal * .029 };
case 'ca': return subTotal => { subTotal * .075 };
}
}
let taxFunc = salesTaxFunc('ca');
getTotal(lineItems, taxFunc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment