Created
September 18, 2022 06:52
-
-
Save philiplambok/7247fb43694d8e8015d2484f9faef184 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 { | |
words := strings.Split(s, " ") | |
var count int | |
word_maps := make(map[string]int) | |
for _, word := range words{ | |
el, ok := word_maps[word] | |
if(ok) { | |
count = el + 1 | |
} else { | |
count = 1 | |
} | |
word_maps[word] = count | |
} | |
return word_maps | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment