-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_sort.html
39 lines (33 loc) · 895 Bytes
/
array_sort.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
<!-- bubble sort -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array Sort</title>
</head>
<body>
<script>
let data= [70,60,10,100,20,200];
// for (let i = 0; i < data.length; i++) {
// for (let j = 0; j < data.length; j++) {
// if(data[j]>data[j+1]){
// let temp = data[j]
// data[j]=data[j+1]
// data[j+1]=temp;
// }
// }
// console.log(data)
// }
// this is with forEach loop //
// data.forEach((_, i, arr) => {
// arr.forEach((_, j) => {
// if (arr[j] > arr[j + 1]) {
// [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
// }
// });
// });
console.log(data);
</script>
</body>
</html>