Last active
December 23, 2017 22:52
-
-
Save kangax/f5afa9b6b7c3e600fb97af16cabe70ca to your computer and use it in GitHub Desktop.
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
// https://www.reuters.com/article/us-usa-tax-provisions-factbox/whats-in-the-final-republican-tax-bill-idUSKBN1ED27K | |
// 10 percent up to $9,525, versus 10 percent up to $9,325 under existing law; | |
// 12 percent from $9,526 to $38,700, versus 15 percent on $9,326 to $37,950; | |
// 22 percent on $38,701 to $82,500, versus 25 percent on $37,951 to $91,900; | |
// 24 percent on $82,501 to $157,500, versus 28 percent on $91,901 to $191,650; | |
// 32 percent on $157,501 to $200,000, versus 33 percent on $191,651 to $416,700; | |
// 35 percent on $200,001 to $500,000, versus 35 percent on $416,701 to $418,400; | |
function calcTax(income) { | |
const brackets = [ | |
{ tax: 0.35, income: 200000 }, | |
{ tax: 0.32, income: 157501 }, | |
{ tax: 0.24, income: 82500 }, | |
{ tax: 0.22, income: 38700 }, | |
{ tax: 0.12, income: 9525 }, | |
{ tax: 0.1, income: 0 }, | |
]; | |
const oldBrackets = [ | |
{ tax: 0.35, income: 416701 }, | |
{ tax: 0.33, income: 191651 }, | |
{ tax: 0.28, income: 91901 }, | |
{ tax: 0.25, income: 37951 }, | |
{ tax: 0.15, income: 9326 }, | |
{ tax: 0.1, income: 0 }, | |
]; | |
function getTax(brackets, income) { | |
console.log('Calculating tax for brackets'); | |
let totalTax = 0; | |
brackets.forEach(bracket => { | |
const incomeInBracket = income - bracket.income; | |
let taxInBracket; | |
if (incomeInBracket > 0) { | |
taxInBracket = incomeInBracket * bracket.tax; | |
totalTax += taxInBracket; | |
} | |
console.log( | |
`Income in bracket | |
${bracket.income} (of which you have ${Math.max(incomeInBracket, 0)}) | |
taxed at ${bracket.tax} | |
is ${taxInBracket || 'none'} | |
` | |
); | |
// clamp | |
income = Math.min(income, bracket.income); | |
}); | |
return totalTax; | |
} | |
const newTax = getTax(brackets, income); | |
const oldTax = getTax(oldBrackets, income); | |
return ` | |
On your income of ${income} you pay ${newTax.toFixed(2)} in taxes | |
which is ~${(newTax / income).toFixed(2)}%. | |
Before, you paid ${oldTax.toFixed(2)} in taxes | |
which is ~${(oldTax / income).toFixed(2)}%`; | |
} | |
// usage: | |
// calcTax(65000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment