I want the most efficient (in case of speed) solution to remove array of given words from the given string:
So far I have this not working solution:
const excludeWordList = ['the', 'in', 'a', 'an'];
run("the wall into")
run("paintings covered the wall another words into this")
function run(speech) {
for(let a = 0; a < excludeWordList.length; a++) {
speech = speech.replaceAll(excludeWordList[a], '');
}
console.log(speech);
}
As you see the code has three major issues:
It removes characters inside the words not just the single words
The result is not a trimmed string we have extra spaces inside words of the result too
The code is not the most efficient way I think!!!, because I need to loop through all the
excludeWordListarray.
I wrote my function as my and as you see the Gainza function is the most efficient function in this case:
