-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathduplicates.html
53 lines (40 loc) · 1 KB
/
duplicates.html
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Remove Duplicates</title>
</head>
<body>
<div id="wrapper">
<p></p>
</div>
<script>
let input = [12,46,232,75,23,12,45,46,232]
//Expected Output: [12,46,232,75,23,45]
let output = []
input.forEach((number) => {
if(output.length === 0)
output.push(number);
let isDuplicate = 0
output.forEach((n) => {
if(number === n)
isDuplicate = 1
})
if(isDuplicate === 0)
output.push(number)
})
console.log(output)
/******************* 2nd Method ********************/
// for(let i=0;i<input.length;i++){
// for(let j=i+1;j<input.length;j++){
// if(input[i] === input[j]){
// input.splice(j,1)
// }
// }
// }
// console.log(input)
</script>
</body>
</html>