Skip to content

Instantly share code, notes, and snippets.

@tarsisazevedo
Last active January 1, 2016 09:59
Show Gist options
  • Save tarsisazevedo/8128051 to your computer and use it in GitHub Desktop.
Save tarsisazevedo/8128051 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 {
words_counted := make(map[string]int)
words := strings.Fields(s)
for _, word := range words {
counts := 0
for i := 0; i < len(words); i++ {
if word == words[i] {
counts += 1
}
}
words_counted[word] = counts
}
return words_counted
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment