Viết hàm nhận mảng chuỗi, đếm tổng số nguyên âm (a,e,i,o,u) trong tất cả chuỗi.
Ví dụ
Mã minh họa:
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));Kết quả
Đầu ra:
10