Last active
May 11, 2019 05:05
-
-
Save tae0y/ebecbab6a94f4de6ab657b5c05596299 to your computer and use it in GitHub Desktop.
gotour map exercise
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 { | |
wordmap := make(map[string]int) | |
sarr := strings.Fields(s) | |
for _, value := range sarr{ | |
_, ok := wordmap[value] | |
if(ok){ | |
wordmap[value]++ | |
}else{ | |
wordmap[value]=1 | |
} | |
} | |
return wordmap | |
} | |
func main() { | |
wc.Test(WordCount) | |
} | |
// pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment