Skip to content

Commit 52b832b

Browse files
Create Count Duplicate Elements.md
1 parent bb62d6c commit 52b832b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

JS-Algo/Count Duplicate Elements.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<img width="520" alt="Screen Shot 2022-03-08 at 18 45 31" src="https://user-images.githubusercontent.com/37787994/157356147-149dbcaf-5084-4f59-83aa-9d9c9124f7e0.png">
2+
<img width="520" alt="Screen Shot 2022-03-08 at 18 45 42" src="https://user-images.githubusercontent.com/37787994/157356150-682279a5-5e8b-4474-a57a-48c6c28db7e0.png">
3+
4+
```js
5+
function countDuplicate(numbers) {
6+
// Write your code here
7+
let counts = {};
8+
let counter = 0;
9+
numbers.forEach(function(x) {
10+
counts[x] = (counts[x] || 0) + 1;
11+
});
12+
13+
for(let key in counts) {
14+
if(counts[key] !== 1) {
15+
counter++;
16+
}
17+
}
18+
19+
return counter;
20+
21+
}
22+
23+
```

0 commit comments

Comments
 (0)