Skip to content

Instantly share code, notes, and snippets.

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