Last active
September 17, 2015 05:58
-
-
Save bradurani/cfe2fb2fcd3b3dd335be to your computer and use it in GitHub Desktop.
Function Factory After
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 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