Skip to content

Instantly share code, notes, and snippets.

@dhoss
Created November 18, 2013 18:26
Show Gist options
  • Save dhoss/7532777 to your computer and use it in GitHub Desktop.
Save dhoss/7532777 to your computer and use it in GitHub Desktop.
Tour of Go (http://tour.golang.org) word count with maps solution
package main
import (
"strings"
"code.google.com/p/go-tour/wc"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
wordCount := make(map[string]int)
for i := range words {
wordCount[words[i]]++
}
return wordCount
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment