Skip to content

Instantly share code, notes, and snippets.

@kamatama41
Created August 27, 2014 06:10
Show Gist options
  • Save kamatama41/723f5a1cc571af45ff7b to your computer and use it in GitHub Desktop.
Save kamatama41/723f5a1cc571af45ff7b to your computer and use it in GitHub Desktop.
My answer of "a tour of Go #41( http://go-tour-jp.appspot.com/#41 )"
package main
import (
"strings"
"code.google.com/p/go-tour/wc"
)
func WordCount(s string) map[string]int {
countMap := make(map[string]int)
for _, word := range strings.Fields(s) {
countMap[word] = countMap[word] + 1
}
return countMap
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment