-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (34 loc) · 1.04 KB
/
index.js
File metadata and controls
39 lines (34 loc) · 1.04 KB
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
const arr = [2, 5, 3, 0, 57, 9, 12, 13];
class Sorting {
constructor() {
this.arr = arr;
}
normalSort_WithThird_Variable() {
for(let i = 0; i < this.arr.length; i++) {
for(let j = i; j < this.arr.length; j++) {
if(this.arr[i] > this.arr[j]) {
let temp = this.arr[i];
this.arr[i] = this.arr[j];
this.arr[j] = temp;
}
}
}
}
normalSort_WithOutThird_Variable() {
for(let i = 0; i < this.arr.length; i++) {
for(let j = i + 1; j < this.arr.length; j++) {
if(this.arr[i] > this.arr[j]) {
this.arr[i] = this.arr[i] + this.arr[j];
this.arr[j] = this.arr[i] - this.arr[j];
this.arr[i] = this.arr[i] - this.arr[j];
}
}
}
}
printSort() {
return this.arr;
}
}
const sortFunction = new Sorting();
sortFunction.normalSort_WithOutThird_Variable();
console.log(sortFunction.printSort());