Created
July 3, 2014 13:13
-
-
Save Centaur/1f07f767bc13d6872e36 to your computer and use it in GitHub Desktop.
forAttendre
This file contains hidden or 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
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