Facing a seemingly simple problem that's proving tricky to solve.
I have an array of product names and a sentence. The goal is to remove any product names from the sentence if they appear in it.
const products = ["premium t-shirt", "t-shirt", "sweatshirt", "baseball tee", "v-neck t-shirt", "long sleeve t-shirt", "raglan baseball tee", "pullover hoodie", "tank top", "zip hoodie",
"hoodie", "shirt", "tee", "tshirt"];
const name = "I'd Rather Be Beekeeping Save The Bees Honey Bee Beehive Zip Hoodie T-Shirt".toLowerCase();
let strippedName;
products.forEach(p => {
if(name.includes(p)) strippedName = name.replace(p, "");
});
The code successfully removes the word shirt but not t-shirt as expected. However, there is also the challenge of iterating over the strippedName variable rather than the original name.
Any suggestions on how to improve this solution?