JSFiddle - React, Tailwind, and code Playground
JavaScript
function sockMerchant(n, ar) {
ar.sort(function(a, b){
return a - b;
});
let count = 0;
for (var i = 0; i < ar.length; i++) {
if (ar[i] === ar[i + 1]) {
count++
i++;
}
}
return count;
}
let dome = [10, 20, 20, 10, 10, 30, 50, 10, 20];
console.log(sockMerchant(9, dome));