Skip to content

Commit

Permalink
solved magic number issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Granello committed Aug 26, 2024
1 parent 2e11719 commit 456c7b1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/models/Mortgage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ export class Mortgage {
remainingBalance: remainingBalance,
},
];

const finalYear = this.termYears - 2;
for (let i = 0; i < this.termYears - 1; i++) {
if (i != this.termYears - 2) {
yearlyPayment = this.monthlyPayment * MONTHS_PER_YEAR;
} else {
// last year just pay the remaining balance
if (i == finalYear) {
yearlyPayment = remainingBalance;
} else {
yearlyPayment = this.monthlyPayment * MONTHS_PER_YEAR;
}

cumulativePaid = cumulativePaid + yearlyPayment;
Expand Down

0 comments on commit 456c7b1

Please sign in to comment.