Skip to content

Files

Latest commit

52b832b · Mar 9, 2022

History

History
23 lines (18 loc) · 672 Bytes

Count Duplicate Elements.md

File metadata and controls

23 lines (18 loc) · 672 Bytes

Screen Shot 2022-03-08 at 18 45 31

Screen Shot 2022-03-08 at 18 45 42

function countDuplicate(numbers) {
    // Write your code here
    let counts = {};
    let counter = 0;
    numbers.forEach(function(x) {
        counts[x] = (counts[x] || 0) + 1;
    });
    
    for(let key in counts) {
        if(counts[key] !== 1) {
            counter++;
        }
    }
    
    return counter;
    
}