So I came up with this, though the counter is not working properly.
const stringVowel = ('hottentottententententoonstellingsbedrijfsacademie')
const letters = stringVowel.split('');
const numberOfVowels = arr => arr.map(num => {
let counter = 0;
if (num === 'a' || num === 'o' || num === 'u' || num === 'e' || num === 'i') {
counter++
}
console.log(counter)
})
numberOfVowels(letters)
One option is to use the string match method and provide a regular expression with all the vowels:
const withVowels = 'hottentottententententoonstellingsbedrijfsacademie';
const noVowels = 'wqdftzsqq';
function numberOfVowels(str) {
return str.match(/[aeiou]/ig)?.length ?? 0;
}
console.log(numberOfVowels(withVowels));
console.log(numberOfVowels(noVowels));
Edit: Updated to a more robust solution based on comments