Skip to content

Instantly share code, notes, and snippets.

@tae0y
Last active May 11, 2019 05:05
Show Gist options
  • Save tae0y/ebecbab6a94f4de6ab657b5c05596299 to your computer and use it in GitHub Desktop.
Save tae0y/ebecbab6a94f4de6ab657b5c05596299 to your computer and use it in GitHub Desktop.
gotour map exercise
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
wordmap := make(map[string]int)
sarr := strings.Fields(s)
for _, value := range sarr{
_, ok := wordmap[value]
if(ok){
wordmap[value]++
}else{
wordmap[value]=1
}
}
return wordmap
}
func main() {
wc.Test(WordCount)
}
// pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment