-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path15.js
More file actions
39 lines (31 loc) · 718 Bytes
/
15.js
File metadata and controls
39 lines (31 loc) · 718 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
29
30
31
32
33
34
35
36
37
38
39
// delete duplicate elements in an array
let array = [1, 2, 3, 2, 4, 5, 6, 7];
let length = array.length;
let temp;
let user = 2;
//removed duplicate variables.
for (i = 0; i < length; i++) {
let flag = false
for (j = i + 1; j < length; j++) {
if (array[i] === array[j]) {
flag = true;
}
}
if (flag) {
for (k = i; k < length; k++) {
array[k] = array[k + 1]
}
length--;
}
}
// sorting
for (i = 0; i < length; i++) {
for (j = i + 1; j < length; j++) {
if (array[i] > array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
console.log(array[user - 1])