Vowel Count

Lee·2022년 8월 1일

Algorithm

목록 보기
63/92
post-thumbnail

❓ Vowel Count

Q. 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.

✔ Solution

//#my solution
function getCount(str) {
  let c=0;
  for(let i=0; i<str.length;i++){
    switch(str[i]){
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
        c++;
        break;
        default:
        break;
    } 
  }
  return c;
}

//other solution
function getCount(str) {
 return str.split('').filter(c => "aeiouAEIOU".includes(c)).length;
}
profile
Lee

0개의 댓글