JSFiddle - React, Tailwind, and code Playground
by Akram kamal
HTML
<div id="result"></div>
<div id="result">====================</div>
<div id="mgresult"></div>
JavaScript
var str2 = '37 39 53 68 75 3 49 61 62 68 23 25 28 30 75 31 35 41 65 66 9 15 24 39 41 11 29 36 58 67 3 50 57 58 60 2 14 21 28 55 5 35 37 41 66 21 31 43 56 60 11 37 46 64 68 2 32 35 50 59 16 29 46 48 55 3 20 34 58 67 3 16 52 54 61 17 26 35 46 62 21 24 25 40 43 16 25 27 29 34 25 45 51 53 73 18 28 33 36 42 25 34 55 70 71 7 12 20 24 59 1 8 54 69 72 3 26 45 58 73 29 31 51 60 64';
var mg = '2 5 5 5 4 2 5 3 5 4 3 5 3 3 5 5 5 2 2 3 4 2 3 2 5';
var res2 = str2.split(" ").map(function(v){return +v}).sort(function (a,b) {
return a - b;
});
var mg2 = mg.split(" ").map(function(v){return +v}).sort(function (a,b) {
return a - b;
});
function findOccurrences(arr, val) {
return arr.filter(function(v){ return v===val}).length
}
for ( var i = 0; i < res2.length; i++ ) {
if (res2[i]!==res2[i-1]) {
console.log(res2[i] + ' ------->' + findOccurrences(res2, res2[i]));
var t1 = "<div>"+res2[i] + ' ------->' + findOccurrences(res2, res2[i])+"</div>";
document.getElementById('result').innerHTML += t1;
}
}
console.log("%cGreen text on yellow background.", "color:green; background-color:yellow");
for ( var j = 0; j < mg2.length; j++ ) {
if ( mg2[j]!== mg2[j-1]) {
console.log('%c'+ mg2[j] + ' ------->' + findOccurrences(res2, mg2[j]), "color:red");
var t2 = "<div>"+ mg2[j] + ' ------->' + findOccurrences( mg2, mg2[j])+"</div>";
document.getElementById('mgresult').innerHTML += t2;
}
}