September 2018
Intermediate to advanced
398 pages
9h 43m
English
In the TDD approach, it is common to refactor the code once we have passing tests. If our test coverage is good, we should not have any fear of changing the code, because any mishap should be flagged by a failing test. This is known as a Red-Green-Refactor cycle.
Change the body of futureCapital with the following code:
def futureCapital(interestRate: Double, nbOfMonths: Int, netIncome: Int, currentExpenses: Int, initialCapital: Double): Double = { val monthlySavings = netIncome - currentExpenses (0 until nbOfMonths).foldLeft(initialCapital)( (accumulated, _) => accumulated * (1 + interestRate) + monthlySavings)}
Here, we have inlined the nextCapital function in the foldLeft call. In Scala, we can define an ...
Read now
Unlock full access