evan058

With HashMap (Scala)

Jun 16th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.20 KB | None | 0 0
  1. scala> List(4,5,5,5,10,13,13).foldLeft(Map.empty[Int, Int].withDefaultValue(0)){(acc, x) => acc + (x -> (acc(x) + 1))}
  2. res0: scala.collection.immutable.Map[Int,Int] = Map(4 -> 1, 5 -> 3, 10 -> 1, 13 -> 2)
Advertisement
Add Comment
Please, Sign In to add comment