Created
April 11, 2013 09:57
-
-
Save royling/0b215ea03fe6be49370f to your computer and use it in GitHub Desktop.
Implement WordCount. It should return a map of the counts of each “word” in the string s.
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
package main | |
import ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
m := make(map[string]int) | |
words := strings.Fields(s) | |
for _, w := range words { | |
m[w] += 1 | |
} | |
return m | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment