Любомир обнови решението на 18.10.2014 17:08 (преди над 3 години)
+package main
+
+import (
+ "sort"
+ "strings"
+)
+
+func getMostCommonWords(text string, wordCountLimit int) []string {
+ lowerText := strings.ToLower(text)
+ splittedText := strings.Fields(lowerText)
+ wordCountMap := countWordsInSlice(splittedText)
+ wordsWithLargerCountThanN := getWordsWithLargerCountThanN(wordCountMap, wordCountLimit)
+ sort.Strings(wordsWithLargerCountThanN)
+ return wordsWithLargerCountThanN
+}
+
+func countWordsInSlice(text []string) map[string]int {
+ wordCountMap := make(map[string]int)
+ for _, word := range text {
+ if _, ok := wordCountMap[word]; !ok {
+ wordCountMap[word] = 0
+ }
+ wordCountMap[word] += 1
+ }
+ return wordCountMap
+}
+
+func getWordsWithLargerCountThanN(wordCount map[string]int, n int) []string {
+ words := []string{}
+ for key, value := range wordCount {
+ if value >= n {
+ words = append(words, key)
+ }
+ }
+ return words
+}