일부 알파벳을 포함할 수 있는 문자열을 받는 JavaScript 함수를 작성해야 합니다. 함수는 문자열에 존재하는 모음의 수를 계산하고 반환해야 합니다.
예시
다음은 코드입니다 -
const str = 'this is a string';
const countVowels = (str = '') => {
str = str.toLowerCase();
const legend = 'aeiou';
let count = 0;
for(let i = 0; i < str.length; i++){
const el = str[i];
if(!legend.includes(el)){
continue;
};
count++;
};
return count;
};
console.log(countVowels(str)); 출력
다음은 콘솔의 출력입니다 -
4