Count array duplicates and display the result.
JavaScript
const arr = [1, 1, 2, 3, 3, 4, 5];
function countArray(arr){
const duplicate = [];
const count = {};
for(let item of arr){
count[item] = (count[item] || 0) + 1;
}
for(let key in count) {
if (count[key] > 1) {
duplicates.push(Number(key));
}
}
console.log(count)
}
console.log(countArray(arr))
//output: 1-2, 2-1, 3-2, 4-1, 5-1