Created
June 6, 2018 20:44
-
-
Save par6n/9f6905c2212364e633c8efcfa4a5f7ec 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 { | |
fields := strings.Fields( s ) | |
output := map[string]int{} | |
for _,v := range fields { | |
if _, exists := output[v]; exists { | |
output[v] = 1 | |
} else { | |
output[v] += 1 | |
} | |
} | |
return output | |
} | |
func main() { | |
wc.Test(WordCount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment