Advertisement
Guest User

Untitled

a guest
Mar 9th, 2025
17
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. const vowels = ["a", "e", "i", "o", "u"];
  3.  
  4. function removeVowels(list) {
  5.   const filteredWordList = [];
  6.  
  7.   // loop through each entry of the list, assigning it to "word".
  8.   list.forEach((word) => {
  9.     let newWord = [];
  10.  
  11.     // split word into an array of letters, and loop over each letter.
  12.     word.split("").forEach((letter) => {
  13.       // check if the array of vowels we made, doesn't include the letter.
  14.       // We use .toLowerCase() to ensure case-insensitivity
  15.       // i.e. ensure that "A" would match against the "a" in the vowel array.
  16.       if (!vowels.includes(letter.toLowerCase())) {
  17.         newWord.push(letter);
  18.       }
  19.     });
  20.  
  21.     filteredWordList.push(newWord.join(""));
  22.   });
  23.  
  24.   return filteredWordList;
  25. }
  26.  
  27. console.log(removeVowels(words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement