Skip to content

Instantly share code, notes, and snippets.

@jacobbf
Last active April 17, 2022 21:56
Show Gist options
  • Save jacobbf/8694bcd77b1936bb32e3049e49f64b20 to your computer and use it in GitHub Desktop.
Save jacobbf/8694bcd77b1936bb32e3049e49f64b20 to your computer and use it in GitHub Desktop.
2022 estimated tax calculator for individuals filing in New York City. Looking for another government body? Put together the JSON and drop a link in a comment.
const gov = {
federal: [
{
threshold: 0,
rate: .10,
},
{
threshold: 9950,
rate: .12,
},
{
threshold: 40525,
rate: .22
},
{
threshold: 86375,
rate: .24
},
{
threshold: 164925,
rate: .32
},
{
threshold: 209425,
rate: .35,
},
{
threshold: 523600,
rate: .37
}
],
nys: [
{
threshold: 0,
rate: .04
},
{
threshold: 8500,
rate: .045
},
{
threshold: 11700,
rate: .0525
},
{
threshold: 13900,
rate: .059
},
{
threshold: 21400,
rate: .0597
},
{
threshold: 80650,
rate: .0633
},
{
threshold: 215400,
rate: .0685
},
{
threshold: 1077550,
rate: .0965
},
{
threshold: 5000000,
rate: .1030
},
{
threshold: 25000000,
rate: .1090
}
],
nyc: [
{
threshold: 0,
rate: .03078
},
{
threshold: 21600,
rate: .03762
},
{
threshold: 45000,
rate: .03819
},
{
threshold: 90000,
rate: .03876
}
]
}
function TAXES(total, body = 'federal') {
let income = total;
const brackets = gov[body].reverse();
const values = brackets.map(bracket => {
if (income > bracket.threshold) {
const inBracketIncome = income - bracket.threshold;
income = income - inBracketIncome;
return inBracketIncome * bracket.rate;
} else {
return 0;
}
})
return values.reduce((curr, a) => curr + a, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment