Created
September 6, 2019 16:14
-
-
Save masautt/1109907cf23eaae3d9e981f190ff938d to your computer and use it in GitHub Desktop.
How to get number of vowels and consonants in JavaScript?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getLetters(words) { | |
var words = (typeof words == 'string') ? words : '', | |
count = re => (words.match(re) || []).length, | |
vowels = count(/[aeiou]/ig), | |
consonants = count(/[bcdfghjklmnpqrstvxzwy]/ig); | |
return {vowels, consonants}; | |
} | |
console.log(getLetters("Marek Sautter")); // --> { vowels: 5, consonants: 7 } | |
// https://codereview.stackexchange.com/questions/128121/count-the-number-of-vowels-and-consonants |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment