Characters frequency

Report a typo

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?

Sample Input 1:

abc

Sample Output 1:

a -> 1,b -> 1,c -> 1
Write 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(","))
}
___

Create a free account to access the full topic