Created
May 3, 2014 08:01
-
-
Save kimitoboku/11493597 to your computer and use it in GitHub Desktop.
A Tour of Go#41
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 { | |
words := strings.Split(s, " ") | |
m := make(map[string]int) | |
for _, str := range words { | |
_, exist := m[str] | |
if exist == false { | |
m[str] = 1 | |
} else { | |
m[str] = m[str] + 1 | |
} | |
} | |
return m | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment