Last active
January 1, 2016 09:59
-
-
Save tarsisazevedo/8128051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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