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

Airflow 動手玩:(一)簡介

Airflow 動手玩:(一)簡介

React(7) - composition

React(7) - composition

[Day 7] JS in Pipeline (7): CI/CD pipeline (2) (Fin.)

[Day 7] JS in Pipeline (7): CI/CD pipeline (2) (Fin.)


Comments