Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const words = ["red", "yellow", "green", "blue", "purple", "radish", "rainbow"];
- function removeVowels(list) {
- const filteredWordList = [];
- for (let i = 0; i < list.length; i++) {
- const word = list[i];
- let newWord = [];
- for (let j = 0; j < word.length; j++) {
- const letter = word[j];
- // the if statement he is essentially the same as what you did with your else if chain.
- // it's basically checking that it isn't any of the vowels.
- if (
- letter !== "a" &&
- letter !== "e" &&
- letter !== "i" &&
- letter !== "o" &&
- letter !== "u"
- ) {
- // Push the letter into the word array.
- // Assuming code.org has it's own syntax you could do appendItem(newWord, letter) from what i understood from your usage of it.
- newWord.push(letter);
- }
- }
- // Here we're pushing newWord.join(""),
- // this means we're taking the array of letters, and joining them together into a word, before pushing it into the filtered word list.
- // We could have had newWord be an empty string instead,
- // then concatenating each letter in the if statement earlier instead of pushing. (newWord += letter; instead of newWord.push(letter))
- filteredWordList.push(newWord.join(""));
- }
- return filteredWordList;
- }
- console.log(removeVowels(words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement