-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathselection.js
45 lines (43 loc) · 1.46 KB
/
selection.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
async function selection() {
const e = document.querySelectorAll(".bar");
for (let i = 0; i < e.length; i++) {
let k = i;
e[i].style.background = "--bars-sorting-blue-color";
for (let j = i + 1; j < e.length; j++) {
e[j].style.background = "yellow";
await waitForMe(delay);
if (parseInt(e[j].style.height) < parseInt(e[k].style.height)) {
if (k !== i) {
e[k].style.background = "var(--bars-color)";
}
k = j;
}
else {
e[j].style.background = "var(--bars-color)";
}
}
await waitForMe(delay);
swap(e[k], e[i]);
e[k].style.background = "var(--bars-color)";
e[i].style.background = "var(--bars-sorted-color)";
}
}
const select = document.querySelector(".selectionSort");
select.addEventListener("click", async function () {
disableSortBtn();
disableSizeSlider();
disableNewArrayBtn();
diablePerformanceBtn()
const startTime = performance.now();
await selection();
const endTime = performance.now();
console.log(`Call to doSomething took ${endTime - startTime} milliseconds.`);
var text = document.getElementById("content");
const p = document.querySelectorAll(".bar");
var time = (endTime - startTime)/1000;
text.textContent = "Array Consist of "+ p.length+" elements and got sorted in "+time.toPrecision(2)+" seconds with a Speed Delay of " + delay+" miliseconds.";
enableSortBtn();
enablePerformanceBtn()
enableNewArrayBtn();
enableSizeSlider();
});