📅  最后修改于: 2022-03-11 15:03:42.528000             🧑  作者: Mango
// how to count number of duplicate pairs in array javascript
function countNumberOfPairs(arr) {
let pairsCount = 0;
let counterObj = {};
for (let num of arr) {
if (!counterObj[num]) {
counterObj[num] = 1;
} else {
counterObj[num] = counterObj[num] + 1;
if (counterObj[num] === 2) {
pairsCount++;
counterObj[num] = 0;
}
}
}
return pairsCount;
}