Created
July 18, 2019 03:49
-
-
Save mahees/e827858ca55877075a2a71bd0c802d65 to your computer and use it in GitHub Desktop.
tax-calculator-breakdowns-brackets
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
'use strict'; | |
const personalAllowance = 25000; | |
const calculateTaxes = (taxBrackets, taxableAllowance) => { | |
const taxInfo = taxBrackets.reduce( | |
(accumulator, taxBracket) => { | |
if (accumulator.remainingAmountToBeTaxed <= 0) { | |
return accumulator; | |
} | |
const amtToTax = | |
taxBracket.amount && accumulator.remainingAmountToBeTaxed > taxBracket.amount | |
? taxBracket.amount | |
: accumulator.remainingAmountToBeTaxed; | |
accumulator.taxAccrued += amtToTax * (taxBracket.percent / 100); | |
accumulator.remainingAmountToBeTaxed -= amtToTax; | |
accumulator.breakdowns.push({ | |
taxBracket, | |
amountTaxed: amtToTax, | |
taxAccrued: accumulator.taxAccrued, | |
remainingAmountToBeTaxed: accumulator.remainingAmountToBeTaxed | |
}); | |
return accumulator; | |
}, | |
{ | |
taxAccrued: 0, | |
remainingAmountToBeTaxed: taxableAllowance, | |
breakdowns: [] | |
} | |
); | |
return taxInfo; | |
}; | |
const calcTaxesPreJuly2019 = annualPay => { | |
const taxableAllowance = annualPay - personalAllowance; | |
const taxBrackets = [{ amount: 35000, percent: 16 }, { amount: 15000, percent: 33.5 }, { percent: 40 }]; | |
const taxInfo = calculateTaxes(taxBrackets, taxableAllowance); | |
return taxInfo; | |
}; | |
const calcTaxesPostJuly2019 = annualPay => { | |
const taxableAllowance = annualPay - personalAllowance; | |
const taxBrackets = [{ amount: 50000, percent: 12.5 }, { percent: 33.5 }]; | |
const taxInfo = calculateTaxes(taxBrackets, taxableAllowance); | |
return taxInfo; | |
}; | |
const calcTaxesJan2020 = annualPay => { | |
const taxableAllowance = annualPay - personalAllowance; | |
const taxBrackets = [{ amount: 50000, percent: 12.5 }, { percent: 28.5 }]; | |
const taxInfo = calculateTaxes(taxBrackets, taxableAllowance); | |
return taxInfo; | |
}; | |
console.log(JSON.stringify(calcTaxesPreJuly2019(25001 - 2))); | |
console.log(JSON.stringify(calcTaxesPreJuly2019(25001))); | |
console.log(JSON.stringify(calcTaxesPreJuly2019(150001))); | |
console.log(JSON.stringify(calcTaxesPostJuly2019(150001))); | |
console.log(JSON.stringify(calcTaxesJan2020(150001))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment