DAY6:Vowel Count


Posted by birdbirdmurmur on 2023-07-19

題目連結:

Vowel Count

解題思維:

1.將a、e、i、o、u放進陣列
2.設定一個計數器
3.迴圈遍歷字串的每個字
4.如果有在陣列裡面,計數器+1

解法:

function getCount(str) {
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  let count = 0;

  for (let i = 0; i < str.length; i++) {
    if (vowels.includes(str[i])) {
      count++;
    }
  }
  return count;
}

#javascript #Codewars #includes







Related Posts

[Oracle Debug] SQL Tuning For Dealing with Hard Parse

[Oracle Debug] SQL Tuning For Dealing with Hard Parse

[Windows] telnet 確定 TCP 連接埠為開啟或關閉 #ping # telnet

[Windows] telnet 確定 TCP 連接埠為開啟或關閉 #ping # telnet

Twitch API壞掉惹,害我debug 超久QQ

Twitch API壞掉惹,害我debug 超久QQ


Comments