Readplace

:hammer: Uplift the range for loan amounts greater than $2000.00 · FagnerMartinsBrack/jack-the-moneylender@07f8e7a

GitHub 1 min read
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 @@

77

assert.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) => {

1611

const dollarsAboveThreshold = loanAmount.minus(greaterThan2000.endOfRange);

1712

const interestToPay = greaterThan2000.interestPerDollar.minus(greaterThan2000.previousInterestPerDollar).multipliedBy(dollarsAboveThreshold);

1813

return interestToPay;

@@ -43,8 +38,13 @@

4338

if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) {

4439

let 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+

};

4646

interestAmount = interestAmount.plus(

47-

calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)

47+

calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)

4848

);

49495050

return interestAmount;

@@ -53,8 +53,13 @@

5353

if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) {

5454

let 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+

};

5661

interestAmount = interestAmount.plus(

57-

calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)

62+

calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)

5863

);

5964

interestAmount = interestAmount.plus(

6065

calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)

@@ -66,8 +71,13 @@

6671

if (loanAmount.greaterThan(END_OF_THIRD_RANGE)) {

6772

let 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+

};

6979

interestAmount = interestAmount.plus(

70-

calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)

80+

calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)

7181

);

7282

interestAmount = interestAmount.plus(

7383

calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)