Created
December 12, 2017 20:25
-
-
Save youchen/17b2a3f4649844f537d6e735b30169b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"golang.org/x/tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
sArr := strings.Fields(s) | |
count := make(map[string]int) | |
for index := range sArr { | |
ele, ok := count[sArr[index]] | |
if ok { | |
count[sArr[index]] = ele + 1 | |
} else { | |
count[sArr[index]] = 1 | |
} | |
} | |
return count | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment