Created
October 23, 2013 06:23
-
-
Save satyrius/7113420 to your computer and use it in GitHub Desktop.
A Tour of Go. Exercise: Maps. Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful.
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 { | |
res := make(map[string]int) | |
for _, w := range strings.Fields(s) { | |
res[w]++ | |
} | |
return res | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where can i get wc package?