Last active
September 24, 2018 20:16
-
-
Save spektraldevelopment/f8c6ae88ec4758e86312e11343a69005 to your computer and use it in GitHub Desktop.
JS: Vowels
This file contains 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 vowels(str) { | |
let vowelCount = 0; | |
[...str].forEach((char, i) => { | |
if (/[AEIOUaeiou]/.test(char) === true) { | |
vowelCount += 1; | |
} | |
}); | |
return vowelCount; | |
} | |
//Two liner | |
// function vowels(str) { | |
// const matches = str.match(/[aeiou]/gi); | |
// return matches ? matches.length : 0; | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment