1var TAX_CREDIT_BRACKETS = [ 2 // please list brackets in order 3 { "limit": 500.05, "rate": 0.75 }, 4 { "limit": 1666.82, "rate": 0.50 }, 5 // (a) this is incredibly important to preserve - Finance Ontario explicitly says "0.3333" _not_ 1/3 6 // (b) NOTE: 3,792.22 is the tax credit limit, but 3,400.00 is the limit for a single party 7 { "limit": 3400.00, "rate": 0.3333 }, 8]; 9 10/** 11 * @param {number} donationAmount 12 * @returns {number} 13 */ 14function calculateTaxCredit(donationAmount) { 15 if (donationAmount < 0) { 16 return 0; 17 } 18 var donationAmountCredited = 0; 19 var creditAmount = 0; 20 for (var bracket of TAX_CREDIT_BRACKETS) { 21 var bracketDonationAmount = Math.min(donationAmount, bracket.limit) - donationAmountCredited; 22 creditAmount += bracketDonationAmount * bracket.rate; 23 donationAmountCredited += bracketDonationAmount; 24 } 25 26 return creditAmount; 27} 28 29/** 30 * @param {number} amount 31 * @returns {string} 32 */ 33function formatCurrency(amount) { 34 return amount.toLocaleString('en-CA', { 35 style: 'currency', 36 currency: 'CAD', 37 currencyDisplay: 'narrowSymbol', 38 useGrouping: true 39 }); 40}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.