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

3. java 17  範例目錄

3. java 17 範例目錄

What is the concept of handle in Java?

What is the concept of handle in Java?

Git 基礎

Git 基礎


Comments