JavaScript 数组中元音字母的数量
我们需要编写一个 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP