-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduparray.html
More file actions
28 lines (26 loc) · 749 Bytes
/
duparray.html
File metadata and controls
28 lines (26 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html>
<body>
<script>
count = 0;
var arr1 = []
var arr = [10, 20, 20,10,20, 30, 20, 50, 50, 60, 60,];
for (i = 0; i < arr.length; i++) {
var duplicate = false;
for (j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) {
duplicate = true
}
}
if (duplicate) {
//check if duplicate number was already added to array
if (!(arr1.includes(arr[i]))) {
arr1.push(arr[i])
count++;
}
}
}
document.write("Duplicate count: " + count + "<br>")
document.write(arr1)
</script>
</body>
</html>