Skip to content

Instantly share code, notes, and snippets.

@zacps
Created April 12, 2016 06:19
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 zacps/d459958d80fff114adb22a579328157b to your computer and use it in GitHub Desktop.
Save zacps/d459958d80fff114adb22a579328157b to your computer and use it in GitHub Desktop.
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
fields := strings.Fields(s)
words := make(map[string]int)
for _, v := range fields {
_, exist := words[v]
if exist {
words[v]++
} else {
words[v] = 1
}
}
return words
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment