7. Distinct Words
messages := []string{"Hello world", "hello there", "General Kenobi"}
count := countDistinctWords(messages)Solution
My Solution
package main
import "strings"
func countDistinctWords(messages []string) int {
holder := make(map[string]struct{})
count:=0
for _,words:= range messages{
sepWords:= strings.Fields(words)
for _, word:= range sepWords{
lowered:= strings.ToLower(word)
if _, ok:=holder[lowered]; !ok{
holder[lowered] = struct{}{}
count++
}
}
}
return count
}