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
}
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")
Share your possible solution
Top comments (5)
I learn from wise guy: fun-fun-function reduce is a swish knife of functional programming, in this case:
this function is counting all alphabets in string.
you right!
to work with vowels need filter before this process:
Perfect <3