Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const words = ["red", "yellow", "green", "blue", "purple", "radish", "rainbow"];
- const vowels = ["a", "e", "i", "o", "u"];
- function removeVowels(list) {
- const filteredWordList = [];
- // loop through each entry of the list, assigning it to "word".
- list.forEach((word) => {
- let newWord = [];
- // split word into an array of letters, and loop over each letter.
- word.split("").forEach((letter) => {
- // check if the array of vowels we made, doesn't include the letter.
- // We use .toLowerCase() to ensure case-insensitivity
- // i.e. ensure that "A" would match against the "a" in the vowel array.
- if (!vowels.includes(letter.toLowerCase())) {
- newWord.push(letter);
- }
- });
- filteredWordList.push(newWord.join(""));
- });
- return filteredWordList;
- }
- console.log(removeVowels(words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement