DEV Community

Discussion on: Daily Challenge #3 - Vowel Counter

Collapse
 
margo1993 profile image
margo1993 • Edited

GO

func FindVowelsCount(sentence string) int {
    vowels := []string{"a", "e", "i", "o", "u"}
    lowerCaseSentence := strings.ToLower(sentence)

    vowelsCount := 0
    for _, c := range lowerCaseSentence {
        if contains(vowels, string(c)) {
            vowelsCount++
        }
    }

    return vowelsCount
}

func contains(list []string, item string) bool {
    for _, w := range list {
        if w == item {
            return true
        }
    }
    return false
}