1const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
2
3function countVowels(sentence) {
4 let counts = 0;
5 for(let i = 0; i < vowels.length; i++) {
6 if(vowels.includes(sentence[i])) {
7 counts++;
8 }
9 }
10 return console.log(counts);
11}
12
13countVowels('Hello World');
14countVowels('AaEeIiOoUu');
15countVowels('aaaaa');
1// BEST and FASTER implementation using regex
2const countVowels = (str) => (str.match(/[aeiou]/gi) || []).length