Skip to content

Instantly share code, notes, and snippets.

@vigor-rus
Last active July 14, 2016 15:44
Show Gist options
  • Save vigor-rus/2bea0e386ba0d15339c90abb304876f7 to your computer and use it in GitHub Desktop.
Save vigor-rus/2bea0e386ba0d15339c90abb304876f7 to your computer and use it in GitHub Desktop.
function getCount(words) {
var words = (typeof words == 'string') ? words : '',
count = re => (words.match(re) || []).length, //when match fails to match, it returns null
vowels = count(/[aeiou]/ig), //g - return all matches, not only the first one
consonants = count(/[bcdfghjklmnpqrstvxzwy]/ig);
return {vowels, consonants};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment