-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (73 loc) · 2.43 KB
/
script.js
File metadata and controls
90 lines (73 loc) · 2.43 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function swap(el1, el2) {
let temp = el1.style.height;
el1.style.height = el2.style.height;
el2.style.height = temp;
}
function disableSortingBtn(){
document.querySelector(".bubbleSort").disabled = true;
document.querySelector(".insertionSort").disabled = true;
document.querySelector(".mergeSort").disabled = true;
document.querySelector(".quickSort").disabled = true;
document.querySelector(".selectionSort").disabled = true;
}
function enableSortingBtn(){
document.querySelector(".bubbleSort").disabled = false;
document.querySelector(".insertionSort").disabled = false;
document.querySelector(".mergeSort").disabled = false;
document.querySelector(".quickSort").disabled = false;
document.querySelector(".selectionSort").disabled = false;
}
function disableSizeSlider(){
document.querySelector("#size").disabled = true;
}
function enableSizeSlider(){
document.querySelector("#size").disabled = false;
}
function disableNewArrayBtn(){
document.querySelector("#newarray").disabled = true;
}
function enableNewArrayBtn(){
document.querySelector("#newarray").disabled = false;
}
function waitforme(milisec) {
return new Promise(resolve => {
setTimeout(() => { resolve('') }, milisec);
})
}
var size=document.querySelector('#size');
size.addEventListener('input',function(){
createNewArray(parseInt(size.value));
});
var delay=260;
var speed=document.querySelector('#speed');
speed.addEventListener('input',function(){
delay=320-parseInt(speed.value);
});
let arr=[];
createNewArray();
function createNewArray(noOfBars = 60) {
deleteChild();
array = [];
for (let i = 0; i < noOfBars; i++) {
array.push(Math.floor(Math.random() * 250) + 1);
}
const bars = document.querySelector("#bars");
for (let i = 0; i < noOfBars; i++) {
const bar = document.createElement("div");
bar.style.height = `${array[i]*2}px`;
bar.classList.add('bar');
bar.classList.add('flex-item');
bar.classList.add(`barNo${i}`);
bars.appendChild(bar);
}
}
function deleteChild() {
const bar = document.querySelector("#bars");
bar.innerHTML = '';
}
const newArray = document.querySelector("#newarray");
newArray.addEventListener("click", function(){
enableSortingBtn();
enableSizeSlider();
createNewArray(size.value);
});