Skip to content

Instantly share code, notes, and snippets.

@royling
Created April 11, 2013 09:57
Show Gist options
  • Save royling/0b215ea03fe6be49370f to your computer and use it in GitHub Desktop.
Save royling/0b215ea03fe6be49370f to your computer and use it in GitHub Desktop.
Implement WordCount. It should return a map of the counts of each “word” in the string s.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
words := strings.Fields(s)
for _, w := range words {
m[w] += 1
}
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