Skip to content

Instantly share code, notes, and snippets.

@oldergod
Created September 11, 2014 15:12
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 oldergod/3a28022ed0f0c7648da0 to your computer and use it in GitHub Desktop.
Save oldergod/3a28022ed0f0c7648da0 to your computer and use it in GitHub Desktop.
Tour of Go Maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
array := strings.Fields(s)
m := make(map[string]int)
for _, word := range array {
m[word] = m[word] + 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