![]() |
count a vowel from string |
Introduction:
I am a Javascript developer. Now day javascript has become the most popular worldwide. But many javascript developers do his routine task daily and never try to learn more and improve his skill. So I am thinking to improve his skills and always give challenges and knowledge.
Challenge:
Write a logic for below input:
Input | Output |
---|---|
Javascript Everywhere | 7 |
You are a good developer | 11 |
Challenges | 3 |
Welcome to the blog | 6 |
1)
function getCount(str) {
return (str.toLowerCase().match(/[aieou]/gi) || []).length;
}
2)
function getCount(str) {
return str.length - (str.toLowerCase().replace(/[aeiou]/g, '') || []).length;
}
This is simple logic using "aeiou" pattern and you can directly identify vowel from the string.Many developers try to use loop and indexOf that's also work but it long and more complex than the above program.
This is the blog you find more challenges and other javascript information.