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

利用 Stencil 建構 Web Component

利用 Stencil 建構 Web Component

Laptop Repair Singapore: Navigating the Maze of Technical Glitches with Expert Solutions

Laptop Repair Singapore: Navigating the Maze of Technical Glitches with Expert Solutions

關於 JavaScript Date - 做一個倒數頁面

關於 JavaScript Date - 做一個倒數頁面


Comments