Kyu
New Coder
The code works, but if 2 vowels are next to each other in a word it doesn't remove the second of the two (ex. your becomes yur, I want it to be yr). Also I am using code.org, and it has some functions such as appendItem or removeItem that it uses.
Code:
function removeVowels(list) {
var filteredList = [];
//goes through each word in list, assigns word to a word in the list
for (var i = 0; i < list.length; i++) {
var word = list[i];
var wordWithoutVowels = "";
var wordInList = [];
//takes each letter and splits it into a list
//ex. pizza = ["p", "i", "z", "z", "a"]
for (var j = 0; j < word.length; j++) {
appendItem(wordInList, word[j]);
}
//takes each letter and check if it's a vowel
//if so, it removes it from the list
for (var x = 0; x < wordInList.length; x++) {
if (wordInList[x] == "a") {
removeItem(wordInList, x);
} else if (wordInList[x] == "e") {
removeItem(wordInList, x);
} else if (wordInList[x] == "i") {
removeItem(wordInList, x);
} else if (wordInList[x] == "o") {
removeItem(wordInList, x);
} else if (wordInList[x] == "u") {
removeItem(wordInList, x);
}
}
//takes each letter from the list and combines them back into a word
for (var y = 0; y < wordInList.length; y++) {
wordWithoutVowels += wordInList[y];
}
//adds the word without any vowels into filteredList
appendItem(filteredList, wordWithoutVowels);
//resets the wordWithoutVowels and wordInList variables for the next time the loot repeats
wordWithoutVowels = "";
wordInList = [];
}
//return the filtered list of all the words without any vowels
return filteredList;
}
var testOne = ["pizza", "fart", "fortnite"];
console.log(removeVowels(testOne));
var testTwo = ["goat", "donkey", "gecko"];
console.log(removeVowels(testTwo));
var testThree = ["nithin", "nathan", "aiden", "damian"];
console.log(removeVowels(testThree));