https://www.codewars.com/kata/54ff3102c1bad923760001f3
Codewars - Achieve mastery through coding practice and developer mentorship
Coding practice for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
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.
설명:
주어진 문자열에서 모음의 수를 반환하세요.
이 카타에서 a, e, i, o, u를 모음으로 고려할 것입니다 (y는 아님).
입력 문자열은 소문자 및/또는 공백으로만 구성됩니다.
풀이
function getCount(str) {
let result = str.match(/[aeiou]/g);
if(!result) return 0;
else return result.length;
}
입력된 문자열에서 모음이 존재하는지 확인하고 result가 null이면 0을 반환 아니면 result의 길이를 반환한다.
다른 사람의 좋았던 풀이
function getCount(str) {
return (str.match(/[aeiou]/ig)||[]).length;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Who likes it? (6 kyu) / JavaScript (0) | 2022.10.10 |
---|---|
[Codewars] Convert number to reversed array of digits (8 kyu) / JavaScript (0) | 2022.10.10 |
[Codewars] Array.diff (6 kyu) / JavaScript (0) | 2022.10.09 |
[Codewars] Square Every Digit (7 kyu) / JavaScript (0) | 2022.10.08 |
[Codewars] Bit Counting (6 kyu) / JavaScript (1) | 2022.10.07 |
댓글