Skip to content

Instantly share code, notes, and snippets.

@eranation
Created May 23, 2013 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eranation/5638929 to your computer and use it in GitHub Desktop.
Save eranation/5638929 to your computer and use it in GitHub Desktop.
Solution to the maps exercise at http://tour.golang.org/#40
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