Skip to content

Instantly share code, notes, and snippets.

@AnSavvides
Last active August 29, 2015 14:02
Show Gist options
  • Save AnSavvides/1a745e3b0892fe58cebf to your computer and use it in GitHub Desktop.
Save AnSavvides/1a745e3b0892fe58cebf to your computer and use it in GitHub Desktop.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
stringList := strings.Fields(s)
wordCount := make(map[string]int)
for i := 0; i < len(stringList); i++ {
word := stringList[i]
_, ok := wordCount[word]
if ok {
wordCount[word] += wordCount[word];
} else {
wordCount[word] = 1;
}
}
return wordCount
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment