Created
February 9, 2018 21:27
-
-
Save bandrzejczak/99541db196aae81c0f53a4e142d34263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def makeWordMap(sentences: List[String]): | |
Map[String, List[String]] = { | |
val initMap = Map.empty[String, List[String]] | |
sentences.foldLeft(initMap) { (map1, sentence) => | |
words(sentence).foldLeft(map1) { (map2, word) => | |
map2 + | |
(word -> (sentence :: map2.getOrElse(word, Nil))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment