Readplace

:hammer: Move each range into an array of ranges · FagnerMartinsBrack/jack-the-moneylender@3b1f522

GitHub 1 min read
View original
  • current

This article is too short to summarise.

Original file line numberDiff line numberDiff line change

@@ -18,18 +18,22 @@

1818

const greaterThan5000 = { endOfRange: Money('$5000.00'), interestPerDollar: Money('$0.14'), previousInterestPerDollar: Money('$0.09') };

1919

const greaterThan10000 = { endOfRange: Money('$10000.00'), interestPerDollar: Money('$0.21'), previousInterestPerDollar: Money('$0.14') };

2020
21+

// You can move this into a configuration file so that changes

22+

// in the behavior doesn't require code changes

23+

const ranges = [greaterThan2000, greaterThan5000, greaterThan10000];

24+
2125

let interestAmount = Money('$0.00');

2226
23-

if (loanAmount.greaterThan(Money('$2000.00'))) {

24-

interestAmount = interestAmount.plus(calculateInterest(loanAmount, greaterThan2000));

27+

if (loanAmount.greaterThan(ranges[0].endOfRange)) {

28+

interestAmount = interestAmount.plus(calculateInterest(loanAmount, ranges[0]));

2529

}

2630
27-

if (loanAmount.greaterThan(Money('$5000.00'))) {

28-

interestAmount = interestAmount.plus(calculateInterest(loanAmount, greaterThan5000));

31+

if (loanAmount.greaterThan(ranges[1].endOfRange)) {

32+

interestAmount = interestAmount.plus(calculateInterest(loanAmount, ranges[1]));

2933

}

3034
31-

if (loanAmount.greaterThan(Money('$10000.00'))) {

32-

interestAmount = interestAmount.plus(calculateInterest(loanAmount, greaterThan10000));

35+

if (loanAmount.greaterThan(ranges[2].endOfRange)) {

36+

interestAmount = interestAmount.plus(calculateInterest(loanAmount, ranges[2]));

3337

}

3438
3539

return interestAmount;