Skip to content

Instantly share code, notes, and snippets.

@espaciomore
Created January 1, 2017 16:52
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 espaciomore/f405b447f3f3f667ca3d130111a31ef3 to your computer and use it in GitHub Desktop.
Save espaciomore/f405b447f3f3f667ca3d130111a31ef3 to your computer and use it in GitHub Desktop.
Go Tour - Word Count
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
wordMap := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
//_, wordExists := wordMap[word]
//if !wordExists {
// wordMap[word] = 1
//} else {
wordMap[word]++
//}
}
return wordMap
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment