Last active
August 29, 2015 14:02
-
-
Save AnSavvides/1a745e3b0892fe58cebf to your computer and use it in GitHub Desktop.
This file contains 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 { | |
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