Skip to content

Instantly share code, notes, and snippets.

@erickhun
Last active August 29, 2015 14:09
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 erickhun/25539167b081f206d363 to your computer and use it in GitHub Desktop.
Save erickhun/25539167b081f206d363 to your computer and use it in GitHub Desktop.
Go Tour Excercice : WordCount with map
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
map_result := make(map[string]int)
splitted := strings.Fields(s)
for _, val:= range splitted {
map_result[val] = map_result[val] + 1
}
return map_result
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment