JSFiddle - React, Tailwind, and code Playground
by henser
JavaScript
function ping(n, ar) {
var count = 1,
total = 0;
ar.sort();
for (let i = 1; n >= i ;i++) {
let val = ar[i-1];
if (val == ar[i]) {
count++;
continue;
}
if (count > 1) {
total += count % 2 == 0 ? count/2 : (count-1)/2;
count = 1;
}
}
return total;
}
console.log(ping(9, [1,1,2,3,1,3,3,3,3]));