I am looking for a way to identify and highlight repetitive sentences within a text area input paragraph. I attempted the following code, but unfortunately, it did not produce the desired result.
highlightRepeatedText(str) {
// Split the string into an array of sentences
const sentencesArray = str.split(".");
// Initialize an empty array to store repeated sentences
let repeatedSentences = [];
// Iterate over the array of sentences
for (let i = 0; i < sentencesArray.length; i++) {
const currentSentence = sentencesArray[i].trim();
// Check if current sentence is already in repeated array, if yes then highlight it
if (repeatedSentences.includes(currentSentence)) {
sentencesArray[i] = `<mark>${currentSentence}</mark>`;
} else {
// If not, add it to the repeated array
repeatedSentences.push(currentSentence);
}
}
// Return the modified string with highlighted repeated sentences
return sentencesArray.join(".");
},