vowelCount

Easy · Loops and Iterations · 4 test cases

Write a function that takes a string and returns the number of vowels it contains. Vowels are 'a', 'e', 'i', 'o', 'u', and should be counted case-insensitively.

Examples

vowelCount('hello world') → 3
vowelCount('JavaScript') → 3
vowelCount('rhythm') → 0

Starter code

function vowelCount(str) {

}

Complexity of the optimal solution

Time O(n), space O(1). The function iterates through the string of length n once. The check `vowels.includes(char)` is a constant time operation for a short fixed string. Thus, time complexity is linear. Space complexity is constant.

Solve vowelCount in the browser