Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- VowelCount is javascript function which takes string as input
- return count of vowels available or 0 if no vowels available
- */
- const VowelCount = (str) =>{
- const vowelArray = ['a', 'e', 'i', 'o', 'u'];
- let counter = 0;
- for (let i = 0; i < vowelArray.length; i++) {
- for (let j = 0; j < str.length; j++) {
- str[j].toLowerCase() == vowelArray[i] && ++ counter
- }
- }
- return counter;
- }
- const VowelCount_Regex = (str) =>{
- return str.match(/a|e|i|o|u/gi) ? str.match(/a|e|i|o|u/gi).length : 0;
- }
- console.log(VowelCount("All cows eat grass")) //5
- console.log(VowelCount("Bxt")) // 0
- console.log(VowelCount_Regex("All cows eat grass")) // 5
- console.log(VowelCount_Regex("Bxt")) // 0
Add Comment
Please, Sign In to add comment