I need help to find the right Scala approach that will make this code more functional and less mutable.
def findMinTime(str: String, timeByCar: Int): Int = {
var myTime = timeByCar
var minTime = timeByCar
str.reverse.foreach { l =>
if (l == 'A') myTime += 3 else myTime -= 2
if (myTime < minTime) minTime = myTime
}
minTime
}