Skip to content

Instantly share code, notes, and snippets.

@FlandreDaisuki
Created August 25, 2014 03:54
Show Gist options
  • Save FlandreDaisuki/25c65c4a84a87625099e to your computer and use it in GitHub Desktop.
Save FlandreDaisuki/25c65c4a84a87625099e to your computer and use it in GitHub Desktop.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
a := strings.Split(s, " ")
res :=make(map[string]int)
for i:=0 ; i<len(a) ; i++ {
_,ok := res[a[i]]
if !ok {
res[a[i]] = 1
} else {
res[a[i]]++
}
}
return res
}
func main() {
wc.Test(WordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment