Skip to content

Instantly share code, notes, and snippets.

@wolftatsu
Last active February 18, 2016 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolftatsu/ea78d0728196dfb24c00 to your computer and use it in GitHub Desktop.
Save wolftatsu/ea78d0728196dfb24c00 to your computer and use it in GitHub Desktop.
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