:hammer: Uplift the range for loan amounts greater than $2000.00 · FagnerMartinsBrack/jack-the-moneylender@07f8e7a
View original- current
Summary (TL;DR)
The diff shows a code refactor where the function `calculateInterestForGreaterThan2000` is changed to accept an object parameter `greaterThan2000` instead of three separate parameters (`endOfRange`, `interestPerDollar`, `previousInterestPerDollar`). The object is defined locally in each calling branch to encapsulate the relevant values for the interest calculation. This change reduces parameter count and improves readability.
@@ -7,12 +7,7 @@
77assert.strictEqual(actual, expected);
88}
9910-const calculateInterestForGreaterThan2000 = (loanAmount, endOfRange, interestPerDollar, previousInterestPerDollar) => {
11-const greaterThan2000 = {
12-endOfRange: endOfRange,
13-interestPerDollar: interestPerDollar,
14-previousInterestPerDollar: previousInterestPerDollar
15-};
10+const calculateInterestForGreaterThan2000 = (loanAmount, greaterThan2000) => {
1611const dollarsAboveThreshold = loanAmount.minus(greaterThan2000.endOfRange);
1712const interestToPay = greaterThan2000.interestPerDollar.minus(greaterThan2000.previousInterestPerDollar).multipliedBy(dollarsAboveThreshold);
1813return interestToPay;
@@ -43,8 +38,13 @@
4338if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) {
4439let interestAmount = Money('$0.00');
454041+const greaterThan2000 = {
42+endOfRange: END_OF_FIRST_RANGE,
43+interestPerDollar: CENTS_FOR_SECOND_RANGE,
44+previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
45+};
4646interestAmount = interestAmount.plus(
47-calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
47+calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
4848);
49495050return interestAmount;
@@ -53,8 +53,13 @@
5353if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) {
5454let interestAmount = Money('$0.00');
555556+const greaterThan2000 = {
57+endOfRange: END_OF_FIRST_RANGE,
58+interestPerDollar: CENTS_FOR_SECOND_RANGE,
59+previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
60+};
5661interestAmount = interestAmount.plus(
57-calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
62+calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
5863);
5964interestAmount = interestAmount.plus(
6065calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)
@@ -66,8 +71,13 @@
6671if (loanAmount.greaterThan(END_OF_THIRD_RANGE)) {
6772let interestAmount = Money('$0.00');
687374+const greaterThan2000 = {
75+endOfRange: END_OF_FIRST_RANGE,
76+interestPerDollar: CENTS_FOR_SECOND_RANGE,
77+previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
78+};
6979interestAmount = interestAmount.plus(
70-calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
80+calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
7181);
7282interestAmount = interestAmount.plus(
7383calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)