We have a function that converts numbers into their string representation inside of provided text. We split the text, and convert numbers, but we need to combine all pieces back on the line. Implement lambda in foldLeft to accumulate pieces into one line.
Lambdas
Stringify the numbers with lambda
Report a typo
Sample Input 1:
Lorem 3 ipsum 4 dolor 7 sit 8 amet 0Sample Output 1:
Text: Lorem three ipsum four dolor seven sit eight amet zeroWrite a program in Scala 3
def convertNumbersToNumString(text: String): String =
text
.split(" ")
.map {
case "0" => "zero"
case "1" => "one"
case "2" => "two"
case "3" => "three"
case "4" => "four"
case "5" => "five"
case "6" => "six"
case "7" => "seven"
case "8" => "eight"
case "9" => "nine"
case word => word
}
.toList
.foldLeft("Text:") { ??? }
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.