I am trying to print the total number of duplicates in the array. Instead the total number of elements is printing from the array instead of the duplicates that are there
const ar = [10, 20, 20, 10, 10, 30, 50, 10, 20];
function pairs(a) {
var pairCount = 0;
for (var i = 0; i < ar.length; i++) {
for (var j = i + 1; j < ar.length; j++) {
if (ar[i] === ar[j]) {
pairCount++;
}
}
}
return pairCount;
}
console.log(pairs(ar));
a.