我们需要编写一个JavaScript函数,该函数接受一个字符串数组(它们可以是单个字符或更大的字符)。我们的函数应该简单地计算数组中包含的所有元音。
让我们写代码-
const arr = ['Amy','Dolly','Jason','Madison','Patricia'];
const countVowels = (arr = []) => {
const legend = 'aeiou';
const isVowel = c => legend.includes(c);
let count = 0;
arr.forEach(el => {
for(let i = 0; i < el.length; i++){
if(isVowel(el[i])){
count++;
};
};
});
return count;
};
console.log(countVowels(arr));输出结果
控制台中的输出将是-
10