I have a function that removes vowels from a string, and then returns the string. My problem is that where there's two or more consecutive vowels it will only remove one of them. I can run the 'for' loop twice to fix the issues, but that doesn't seem right. Is there anything I could change?
let string = "I'd always thought lightning was something only I could see.";
let vowels = ['a', 'e', 'i', 'o', 'u']
function removeVowels(str) {
let stringArray = str.split('');
for (let letter of stringArray){
if (vowels.includes(letter.toLowerCase())){
let index = stringArray.indexOf(letter);
stringArray.splice(index, 1);
}
}
return stringArray.join('');
}
Returns:
"'d lwys thught lghtnng ws smthng nly culd se."