An Easy Explanation of TFSA Contribution Limits for the Modern JavaScript Developer

If you're like the rest of your fellow coders, you've got way too much money in your chequing account, and not nearly enough time to read those boring financial definitions.

Let's cut the BS and just transpile the English into the only real dev language: JavaScript.

*chugs soylent*

The Algorithm

const limits = { 2009: 5000, 2010: 5000, ... 2019: 6000, ... }; const startYear = getBirthYear() + 18; let room = 0; let withdrawalAccum = 0; account.onWithdrawal = (amount) => { withdrawalAccum += amount; }); account.onDeposit = (amount) => { room -= amount; if (room < 0) { throw 'Shit'; } }); /* Emitted in 2009 onwards. */ calendar.onNewYear = (year) => { room += withdrawalAccum; withdrawalAccum = 0; if (year >= startYear && isCanadianResident()) { room += limits[year]; } });

(Disclaimer: the above is for illustrative purposes and you should consult the official API before using it in production. There are many edge cases.)

Ez-pz.

Comments