Created
August 25, 2014 03:54
-
-
Save FlandreDaisuki/25c65c4a84a87625099e 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 { | |
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