Go exercises: Maps

Jan 10, 2018 11:01


Originally published at Moishe Beshkin. You can comment here or there.

Exercise: Maps

package main import ( "golang.org/x/tour/wc" "strings" ) func WordCount(s string) map[string]int { stringAr := strings.Fields(s) result := make(map[string]int) for i:=range stringAr { v :=result[stringAr[i]] result[stringAr[i]] = v+1 } return result } func main() { wc.Test(WordCount) }

issues and resolutions

Previous post Next post
Up