Stringify the numbers with lambda

Report a typo

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.

Sample Input 1:

Lorem 3 ipsum 4 dolor 7 sit 8 amet 0

Sample Output 1:

Text: Lorem three ipsum four dolor seven sit eight amet zero
Write 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:") { ??? }
___

Create a free account to access the full topic