vowelsCount

codewars kata / refresh

by trentHarlem

JavaScript

function getCount(str) {
  return (str.match(/[aeiou]/ig)||[]).length;
}


function getCount2(str) {
  let vowels = 'aeiou'
  let vowelsCount = 0;

  for (let i = 0; i < str.length; i++) {
    for (let j = 0; j < vowels.length; j++) {
      if (str[i] == vowels[j]) {
        vowelsCount++
      }
    }
  }
  return vowelsCount
}
console.log(getCount('fo guck yourself'), 'Expected: 5 vowels')
console.log(getCount('what the duck'), '3 vowels')