I have strings in an array and need to remove entries that contain strings. But also removing partial matches.
var rawData = ["foo", "bar", "foobar", "barbaz", "boo" ]
var unwantedData = ["foo","baz"]
var cleanData = filter(rawData,unwantedData)
console.log(cleanData)
>>>["bar","boo"]
My current solution is as follows:
function filter(data,filterArray){
return data.filter(rawEntry => {
var t = true; // set to false if index is found
filterArray.forEach(unwantedStr => { t = t && ~rawEntry.indexOf(unwantedStr) ? false : t });
return t; //decides if entry gets removed by filter
});
}
But i feel like there might be a nicer way to do it. This is probably computationally not the most efficient way.