Anzahl der doppelten Paare in Array JavaScript
// 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;
}
Chetan Nada