vowels('Hi There!') //--> 3
vowels('Why do you ask?') //--> 4
vowels('Why?') //--> 0
My Solution
function vowels(str) {
return (str.match(/[aeiou]/gi) || []).length;
}
SG Solution 1
function vowels(str) {
const matches = str.match(/[aeiou]/gi);
return matches ? matches.length : 0;
}
SG Solution 2
function vowels(str) {
let count = 0;
const checker = ['a', 'e', 'i', 'o', 'u'];
for (let char of str.toLowerCase()) {
if (checker.includes(char)) {
count++;
}
}
return count;
}