Created
August 15, 2021 16:28
-
-
Save vishuvenu/42aee60e2162b0630305039168d9da39 to your computer and use it in GitHub Desktop.
WordCount.go
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 ( | |
"golang.org/x/tour/wc" | |
"strings" | |
) | |
func WordCount(s string) map[string]int { | |
wc := make(map[string]int) | |
for _, word := range strings.Split(s, " ") { | |
if _, exist := wc[word]; !exist { | |
wc[word] = 0 | |
} | |
wc[word] += 1 | |
} | |
return wc | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment