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(words) {
- // map over each word in the words array.
- // this is similar to what you did with the for loops.
- // except .map() loops over a copy, rather than the original, to loop over the original use .forEach()
- const filteredWords = words.map(
- // Here we are taking each entry of the array (in this case: word) and checking against a regex, replacing each match with an empty string to remove it.
- // let me explain the regex a bit.
- // the slashes just indicate that its contents is a regex string,
- // the [] means match any of the characters,
- // g means it's global, or find all matches rather than stopping at the first one.
- // i means it's case-insensitive.
- word => word.replace(/[aeiou]/gi, "")
- );
- // return the filtered array. You could place the words.map(...) code here, instead of filteredWords, but for clarity i decided not to.
- return filteredWords;
- }
- console.log(removeVowels(words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement