JS | Count vowel from a String

Logic: First of all we will write a variable that will contain a count of vowels, we will make it initialize it with 0. The main think , We can make a string of all vowels like ‘aeiou’ then we an use includes method with each character as argument to check the string (string of vowels) contain the character or not, if it’s true then we can mark the character as a vowel and we will increment our count variable

Program :

const vowel =  (str) => {  

count = 0;

for(char of str) {
if('aeiou'.includes(char)) {
count++;
}
}
return count;
}
console.log(vowel('hello world')) //3

Keep learning, keep growing!

Let’s connect on LinkedIn!. Please read more for more data structure javascript question.

I am listing the coding interview rounds for Big companies, which are very popular. If you are preparing for an interview or wanted to be in good company, please do check the below questions on Arrays, String and Linked List. I will come up with more interview coding round questions.

Follow me for more coding interview.

--

--