Imagine you're working on a program that finds the frequency of some characters in a source text. We have the initial part of the program but it's missing some core points. Can you finish it?
Defining new collections
Characters frequency
Report a typo
Sample Input 1:
abcSample Output 1:
a -> 1,b -> 1,c -> 1Write a program in Scala 3
object CharactersFrequency extends App {
def build(source: String, result: Map???): Map[Char, Int] =
if (source.nonEmpty) {
val char = source.head
val frequency = result.getOrElse(char, ???) + 1
build(source.tail, ???.updated(char, frequency))
} else result
val input = scala.io.StdIn.readLine()
println(build(input, Map.empty???).mkString(","))
}
___
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.