I have two sets of words:
const words = ['a man', 'a man who', "hiding"];
const speechWords = ["this", "is", "a", "man", "hiding", "under", "blanket", "a", "man", "who", "lives", "here"];
My goal is to search for any exact matches (based on word order) from the words
array within the speechWords
array and create a new combined array like this:
["this", "is", "a man", "hiding", "under", "blanket", "a man who", "lives", "here"]
It's important to note that if a matching phrase from the words
array is found, the corresponding elements from speechWords
should be joined together.
Please Note: The original order of the speechWords
array must remain unchanged.
I attempted to iterate through the words
array, splitting the words and then searching each one individually in another loop over the speechWords
array, but unfortunately, I did not achieve the desired results...