I have a table with results generated using v-html (meaning the text inside the table does not appear until the page is rendered). I want to compare two rows and highlight any duplicate words they may contain.
While looking for examples, I came across a project that showcased what I need, although it was more complex than necessary. This question on Stack Overflow resembles mine, but it requires defining the words rather than letting the page identify them automatically.
For instance, here's an illustration of the desired output:
<table>
<tr>
<td v-html="link.orderdesciption">
order:<br />
<mark> TV </mark><br /> <!--note that the contents of the td would not appear in markup due to being v-html-->
PS3 <br />
Laptop
</td>
<td>
qty:<br />
1<br />
2<br />
1<br />
</td>
</tr>
<tr>
<td>
----------------
</td>
<td>
----------------
</td>
</tr>
<tr>
<td v-html="link.orderrecieved">
recieved:<br /> <!--same note as above, v-html only shows-->
<mark> TV </mark><br />
Desktop<br />
</td>
</tr>
</table>
I've been attempting to work on this issue, but I'm unsure about the next steps:
var text = $('td').text(),
words = text.split(' '),
sortedWords = words.slice(0).sort(),
duplicateWords = [];
for (var i=0; i<sortedWords.length-1; i++) {
if (sortedWords[i+1] == sortedWords[i]) {
duplicateWords.push(sortedWords[i]);
}
}
duplicateWords = $.unique(duplicateWords);
Any advice or guidance would be greatly appreciated,