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