-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
47 lines (41 loc) · 1.36 KB
/
helper.js
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
"use strict";
class Helper {
constructor(time, list = []) {
this.time = parseInt(400/time);
this.list = list;
}
mark = async (index) => {
this.list[index].setAttribute("class", "cell current");
}
markSpl = async (index) => {
this.list[index].setAttribute("class", "cell min");
}
unmark = async (index) => {
this.list[index].setAttribute("class", "cell");
}
pause = async() => {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, this.time);
});
}
compare = async (index1, index2) => {
await this.pause();
let value1 = Number(this.list[index1].getAttribute("value"));
let value2 = Number(this.list[index2].getAttribute("value"));
if(value1 > value2) {
return true;
}
return false;
}
swap = async (index1, index2) => {
await this.pause();
let value1 = this.list[index1].getAttribute("value");
let value2 = this.list[index2].getAttribute("value");
this.list[index1].setAttribute("value", value2);
this.list[index1].style.height = `${3.8*value2}px`;
this.list[index2].setAttribute("value", value1);
this.list[index2].style.height = `${3.8*value1}px`;
}
};