Advertisement
Guest User

Untitled

a guest
Mar 9th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const words = ["red", "yellow", "green", "blue", "purple", "radish", "rainbow"];
  2.  
  3. function removeVowels(list) {
  4.   const filteredWordList = [];
  5.  
  6.   for (let i = 0; i < list.length; i++) {
  7.     const word = list[i];
  8.     let newWord = [];
  9.  
  10.     for (let j = 0; j < word.length; j++) {
  11.       const letter = word[j];
  12.  
  13.       // the if statement he is essentially the same as what you did with your else if chain.
  14.       // it's basically checking that it isn't any of the vowels.
  15.       if (
  16.         letter !== "a" &&
  17.         letter !== "e" &&
  18.         letter !== "i" &&
  19.         letter !== "o" &&
  20.         letter !== "u"
  21.       ) {
  22.         // Push the letter into the word array.
  23.         // Assuming code.org has it's own syntax you could do appendItem(newWord, letter) from what i understood from your usage of it.
  24.         newWord.push(letter);
  25.       }
  26.     }
  27.  
  28.     // Here we're pushing newWord.join(""),
  29.     // this means we're taking the array of letters, and joining them together into a word, before pushing it into the filtered word list.
  30.     // We could have had newWord be an empty string instead,
  31.     // then concatenating each letter in the if statement earlier instead of pushing. (newWord += letter; instead of newWord.push(letter))
  32.     filteredWordList.push(newWord.join(""));
  33.   }
  34.  
  35.   return filteredWordList;
  36. }
  37.  
  38. console.log(removeVowels(words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement