Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. /*
  2. VowelCount is javascript function which takes string as input
  3. return count of vowels available or 0 if no vowels available
  4. */
  5.  
  6. const VowelCount = (str) =>{
  7. const vowelArray = ['a', 'e', 'i', 'o', 'u'];
  8. let counter = 0;
  9. for (let i = 0; i < vowelArray.length; i++) {
  10. for (let j = 0; j < str.length; j++) {
  11. str[j].toLowerCase() == vowelArray[i] && ++ counter
  12. }
  13. }
  14. return counter;
  15. }
  16.  
  17. const VowelCount_Regex = (str) =>{
  18. return str.match(/a|e|i|o|u/gi) ? str.match(/a|e|i|o|u/gi).length : 0;
  19. }
  20.  
  21. console.log(VowelCount("All cows eat grass")) //5
  22. console.log(VowelCount("Bxt")) // 0
  23.  
  24. console.log(VowelCount_Regex("All cows eat grass")) // 5
  25. console.log(VowelCount_Regex("Bxt")) // 0
Add Comment
Please, Sign In to add comment