How to remove specific words on a string (and add the word “and” if possible) that are repeated twice but only twice and only certain characters?
Example: “Intruction in seated LE AROM x10 each instruction in standing LE AROM x10 each”.
I want it to say, “Instruction in seated LE AROM and standing LE AROM x10 each”.
I have tried looping through it and removing duplicates, but it removes duplicates that I do need. I also tried this that I found from somebody else’s question, but they were just wanting to count how many times a word was repeated, so it didn’t help me much.
function removeDuplicate(str) {
let words = JSON.stringify(str).toLowerCase().split(' ')
let wordsCount = {}
words.forEach(word => {
wordsCount[word] = (wordsCount[word] || 0) + 1
})
}