JavaScript Programming Problem 2

Muhammad Hamza - Oct 25 '20 - - Dev Community

JavaScript Programming Problems Series

I started Programming test series where i will be sharing share commonly asked interview questions and my solution for JavaScript developers .

Problem # 2

Count the number of individual vowels in a given string

you are given a string, count and return the number of vowels used in that string. for example if string has a four times and e two times it must return

{ 
   a:4,
   e:2 
 } 
Enter fullscreen mode Exit fullscreen mode

My Solution

const vowelCount = (str)=>{
    str = str.toLowerCase().split("");
    const vowel = "aeiou";
    const obj = {}

    for(let wo of str){
    if(vowel.indexOf(wo) !== -1){
        if(obj[wo]) {
        obj[wo] ++
        }
        else {
        obj[wo] = 1
        }
      }
    }


return obj
}

vowelCount("3123dasds JJKH e o a eee iJ")
Enter fullscreen mode Exit fullscreen mode

Share your possible solution

. . . . . . . . . . . . . . . . . . . .