Created
May 23, 2013 19:53
-
-
Save eranation/5638929 to your computer and use it in GitHub Desktop.
Solution to the maps exercise at http://tour.golang.org/#40
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 ( | |
"code.google.com/p/go-tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
fields := strings.Fields(s) | |
m := make(map[string]int) | |
for _ , v := range fields { | |
m[v] ++ | |
} | |
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