문자열 배열을 받는 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