题目:
Return the number (count) of vowels in the given string.
We will consider a, e, i, o, and u as vowels for this Kata.
The input string will only consist of lower case letters and/or spaces.
个人感觉较好的解答:
function getCount(str) {
return (str.match(/[aeiou]/ig)||[]).length;
}
function getCount(str) {
return str.replace(/[^aeiou]/gi, '').length;
}
function getCount(str) {
return str.split('').filter(c => "aeiouAEIOU".includes(c)).length;
}
自己的解答:
function getCount(str) {
var vowelsCount = 0;
var vowels = 'aeiou';
for(var i = 0; i < str.length; i++){
if(vowels.includes(str[i])){
vowelsCount ++;
}
}
return vowelsCount;
}