I need to get the most used content text of elements within a certain class. In my case the most recurrent phrase of elements: Service number 1
<div class="service_list">
<span>Service number 1</span>
<span>Service number 2</span>
</div>
<div class="service_list">
<span>Service number 1</span>
<span> Service number 3</span>
</div>
<div class="service_list">
<span>Service number 1</span>
<span> Service number 4</span>
</div>
2
Answers
Hope it works for you.
One approach is below, with explanatory comments in the JavaScript:
JS Fiddle demo.
References:
Array.prototype.filter()
.Array.prototype.forEach()
.Array.prototype.map()
.Array.prototype.sort()
.Array.prototype.reduce()
.document.createDocumentFragment()
.document.createElement()
.document.querySelector()
.Element.append()
.Element.querySelector()
.Element.querySelectorAll()
.Element.remove()
.EventTarget.addEventListener()
.Math.floor()
.Math.random()
.Node.firstChild
.Node.removeChild()
.Object.assign()
.Object.entries()
.String.prototype.trim()
.while
.