알고리즘 | codewars | 모음 갯수 찾기 (Vowel Count)
Return the number (count) of vowels in the given string.
We will considera, e, i, o, uas vowels for this Kata (but not y).
The input string will only consist of lower case letters and/or spaces.
주어진 string에 모음이 몇 개 들어가있는지 확인하는 문제이다.
내 풀이
function getCount(str) {
var vowelsCount = 0;
// enter your majic here
var strArr = str.split('')
strArr.forEach(element => {
switch (element) {
case "a":
vowelsCount++;
break;
case "e":
vowelsCount++;
break;
case "i":
vowelsCount++;
break;
case "o":
vowelsCount++;
break;
case "u":
vowelsCount++;
break;
}
})
return vowelsCount;
}
Best Practice & Clever
function getCount(str) {
return (str.match(/[aeiou]/ig)||[]).length;
}
Author And Source
이 문제에 관하여(알고리즘 | codewars | 모음 갯수 찾기 (Vowel Count)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@xoxobabegirl/알고리즘-모음-갯수-찾기-Vowel-Count저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)