DEV Community

Discussion on: Daily JavaScript Challenge #JS-124: Find Number of Vowels in a String

Collapse
 
justaguyfrombr profile image
Misael Braga de Bitencourt • Edited
const countVowels = word => {
    const vowels = [...'aeiouáéíóúâêîôûàèìòùãẽĩõũ'];
    return [...word.toLowerCase()].reduce((counter, current) => counter += vowels.indexOf(current) === -1 ? 0 : 1, 0);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sqlrob profile image
Robert Myers

Why use spread instead of the string iterator directly?

Collapse
 
justaguyfrombr profile image
Misael Braga de Bitencourt

It is really not necessary. Just for deal it implicityly as a list.