Home > katas > Vowel Count (7kyu) [JavaScript]

Vowel Count (7kyu) [JavaScript]


Chek kata on Codewars

Description:

Return the number (count) of vowels in the given string.

We will consider a, e, i, o, u as vowels for this Kata (but not y).

The input string will only consist of lower case letters and/or spaces.

Loop

function getCount(str) {
  let vowelsCount = 0
  const vowels = ["a", "e", "i", "o", "u"]
  for(let char of str) {
      if(vowels.includes(char)) {
          vowelsCount++
      }
  }

  return vowelsCount;
}

RegEx

function getCount(str) {
    return str.match(/[aeiou]/gi).length
}
© 2021, Andrew Losseff