Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 444 Bytes

README.md

File metadata and controls

16 lines (14 loc) · 444 Bytes

is-vowel

Check if character is a vowel

const isVowel = char => /[aeiou]/i.test(char);

It could be used in a recursion to count vowels in a string

const countVowels = str => !str?.length ? 0 : isVowel(str[0]) + countVowels(str.slice(1));

Regex breakdown

  • / regex boundary
  • [] group bracket expression matching single chars it contains
  • aeiou chars to test against
  • i case insensitive flag