Last active
February 18, 2016 00:46
-
-
Save wolftatsu/ea78d0728196dfb24c00 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 ( | |
"strings" | |
"fmt" | |
"golang.org/x/tour/wc" | |
) | |
func WordCount(s string) map[string]int { | |
// Split word by space | |
word_ary := strings.Split(s, " ") | |
// Create map | |
m := make(map[string]int) | |
// Iterate word_ary and count each by word | |
for _, word := range word_ary { | |
m[word]++ | |
} | |
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