Created
January 28, 2013 17:49
-
-
Save davegardnerisme/4657568 to your computer and use it in GitHub Desktop.
Learning go!
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
| package main | |
| import ( | |
| "tour/wc" | |
| "strings" | |
| ) | |
| func WordCount(s string) map[string]int { | |
| list := strings.Fields(s) | |
| wc := map[string]int{} | |
| for _, value := range list { | |
| _, ok := wc[value] | |
| if !ok { | |
| wc[value] = 0 | |
| } | |
| wc[value]++ | |
| } | |
| return wc | |
| } | |
| func main() { | |
| wc.Test(WordCount) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment