Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jordancalder/af2ec0bdc6fedcf12e4887d20185bfc9 to your computer and use it in GitHub Desktop.
Save jordancalder/af2ec0bdc6fedcf12e4887d20185bfc9 to your computer and use it in GitHub Desktop.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
var words = strings.Split(s, " ")
var mapper map[string]int
mapper = make(map[string]int)
for _, word := range words {
if _, ok := mapper[word]; ok {
mapper[word]++
} else {
mapper[word] = 1
}
}
return mapper
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment