Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created July 3, 2014 13:13
Show Gist options
  • Save Centaur/1f07f767bc13d6872e36 to your computer and use it in GitHub Desktop.
Save Centaur/1f07f767bc13d6872e36 to your computer and use it in GitHub Desktop.
forAttendre
val keywords = Set("class", "public", "private", "protected")
def wordCount(is: java.io.InputStream): Map[String, Int] = {
var result = Map[String, Int]()
val scanner = new java.util.Scanner(is)
while(scanner.hasNext) {
val word = scanner.next
if(keywords.contains(word)) {
if(result.contains(word)) {
result = result.updated(word, 1)
} else {
result = result.updated(word, result(word) + 1)
}
}
}
result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment