Vowel Count
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, u as vowels for this Kata (but not y).
The input string will only consist of lower case letters and/or spaces.
📌 Needs ) 주어진 문자열에서 모음(a, e, i, o, u)의 개수를 반환하라.
📁 Sol )
1. 모음 array 작성
2. for...of문 사용
3. if문 : 조건에 해당하면 개수 +1
4. includes : 배열 항목 중 특정 값이 포함되어 있는지 여부 확인
function getCount(str) {
var vowelsCount = 0;
const vowels = ['a', 'e', 'i', 'o', 'u'];
for(let char of str) {
if(vowels.includes(char)) {
vowelsCount++
}
}
return vowelsCount;
}
💡 Other ways to solve )
str.match
: 문자열이 정규식과 매치되는 부분을 검색function getCount(str) {
return (str.match(/[aeiou]/ig)||[]).length;
}