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');
1const vowelCount = str => {
2 let vowels = /[aeiou]/gi;
3 let result = str.match(vowels);
4 let count = result.length;
5
6 console.log(count);
7};
1function getCount(str) {
2let vowelList = 'AEIOUaeiou'
3let vowelsCount = 0;
4
5 for(var i = 0; i < str.length ; i++)
6 {
7 if (vowelList.indexOf(str[i]) !== -1)
8 {
9 vowelsCount += 1;
10 }
11 }
12 return vowelsCount;
13}
14
1// BEST and FASTER implementation using regex
2const countVowels = (str) => (str.match(/[aeiou]/gi) || []).length