DEV Community

Discussion on: Algorithms: Find the Vowels

Collapse
 
rem113 profile image
Rem113 • Edited

Looks like you are solving it with JS. I would use a more functional style:

function countVowels(text) {
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  return text
    .map(toLowerCase)
    .filter((c) => vowels.includes(c))
    .length();
}
Enter fullscreen mode Exit fullscreen mode

It looks better to me, though yours is perfectly valid.