Skip to content

Instantly share code, notes, and snippets.

@bkbeachlabs
Created December 22, 2017 20:56
Show Gist options
  • Save bkbeachlabs/ca1d82b42a827ccb3c4c5c33e582a4d4 to your computer and use it in GitHub Desktop.
Save bkbeachlabs/ca1d82b42a827ccb3c4c5c33e582a4d4 to your computer and use it in GitHub Desktop.
Calculates your Ontario income tax from a semi-monthly paycheque.
function taxFromSemiMonthlyPaycheque(paychequeAmt) {
var annualized = paychequeAmt * 24;
var annualTax = ontarioTax(annualized) + federalTax(annualized);
return annualTax / 24;
};
/*
* 5.05% on the first $42,201 of taxable income, +
* 9.15% on the next $42,203, +
* 11.16% on the next $65,596, +
* 12.16% on the next $70,000, +
* 13.16 % on the amount over $220,000
*/
var ontarioBrackets = [
{size: 42201, rate: .0505},
{size: 42203, rate: .0915},
{size: 65596, rate: .1116},
{size: 70000, rate: .1216},
{size: 9999999999, rate: .1316}
];
/*
* 15% on the first $45,916 of taxable income, +
* 20.5% on the next $45,915 of taxable income (on the portion of taxable income over $45,916 up to $91,831), +
* 26% on the next $50,522 of taxable income (on the portion of taxable income over $91,831 up to $142,353), +
* 29% on the next $60,447 of taxable income (on the portion of taxable income over $142,353 up to $202,800), +
* 33% of taxable income over $202,800.
*/
var federalBrackets = [
{size: 45916, rate: .15},
{size: 45915, rate: .205},
{size: 50522, rate: .26},
{size: 60447, rate: .29},
{size: 9999999999, rate: .33}
];
function tax(annualIncome, brackets) {
var totalTax = 0;
var remainingIncome = annualIncome;
for (var i=0; i<brackets.length; i++) {
var bracket = brackets[i];
if (remainingIncome <= bracket.size) {
return totalTax + remainingIncome * bracket.rate;
} else {
var bracketMaxTax = bracket.size * bracket.rate;
totalTax += bracketMaxTax;
remainingIncome -= bracket.size;
}
};
throw {};
}
function ontarioTax(annualIncome) {
return tax(annualIncome, ontarioBrackets);
}
function federalTax(annualIncome) {
return tax(annualIncome, federalBrackets);
}
function testTax() {
var result = taxFromSemiMonthlyPaycheque(5000);
console.log(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment