Readplace

:hammer: Create a function to calculate interest greater than $2000.00 · FagnerMartinsBrack/jack-the-moneylender@0dae8d7

GitHub 1 min read
View original
  • current

This article is too short to summarise.

Original file line numberDiff line numberDiff line change

@@ -18,8 +18,12 @@

1818

const CENTS_FOR_FOURTH_RANGE = Money('$0.21');

1919
2020

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

21-

const dollarsAboveThreshold = loanAmount.minus(END_OF_FIRST_RANGE);

22-

const interestAmount = CENTS_FOR_SECOND_RANGE.multipliedBy(dollarsAboveThreshold);

21+

const calculateInterestForGreaterThan2000 = (loanAmount, endOfFirstRange, centsForSecondRange) => {

22+

const dollarsAboveThresholdForGreaterThan2000 = loanAmount.minus(endOfFirstRange);

23+

const interestForGreaterThan2000 = centsForSecondRange.multipliedBy(dollarsAboveThresholdForGreaterThan2000);

24+

return interestForGreaterThan2000;

25+

};

26+

const interestAmount = calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE);

2327

return interestAmount;

2428

}

2529