In go!
func countVowels(s string) int { l := strings.ToLower(s) count := 0 for _, c := range l { switch c { case 'a': fallthrough case 'e': fallthrough case 'i': fallthrough case 'o': fallthrough case 'u': count++ } } return count }
Go playground example
Uses fallthrough mostly because I wanted to, count++ would be smaller, but all cases behave the same (also its more easily maintainable).
fallthrough
count++
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In go!
Go playground example
Uses
fallthrough
mostly because I wanted to,count++
would be smaller, but all cases behave the same (also its more easily maintainable).