-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
71 lines (67 loc) · 2.52 KB
/
app.js
File metadata and controls
71 lines (67 loc) · 2.52 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
let height=[],sortedHeights=[],height_array,children,sze,maxLimit,speed=1;
function addHeightsToDiv(){
document.getElementById("height-array").innerHTML=" ";
height=[];
let rand=0;
maxLimit=300;
sze=document.getElementById("arr_sz").value;
speed=document.getElementById("speed_input").value;
for(let i=0;i<sze;i++){
while(rand==0) rand=Math.floor(Math.random()*maxLimit);
height.push(rand);
rand=0;
}
let new_element,new_h;
let class_name="heights";
for(let i=0;i<sze;i++){
new_element=document.createElement("div");
new_element.classList.add(class_name);
new_h=height[i]+"px";
new_element.style.backgroundColor="red";
new_element.style.width="8px";
new_element.style.height=new_h;
document.getElementById("height-array").appendChild(new_element);
}
sortedHeights=[];
for(let i=0;i<sze;i++) sortedHeights[i]=height[i];
sortedHeights.sort(function(a, b){return a - b});
height_array=document.getElementById("height-array");
children=document.getElementById("height-array").children;
console.log(height);
}
addHeightsToDiv();
document.getElementById("new-array").addEventListener("click",addHeightsToDiv);
let arraySize = document.querySelector('#arr_sz');
arraySize.addEventListener('input', function(){
addHeightsToDiv();
});
let arraySpeed = document.querySelector('#speed_input');
arraySpeed.addEventListener('input', function(){
speed=document.getElementById("speed_input").value;
});
function disableSortingButton(){
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("#arr_sz").disabled = true;
}
function enableSizeSlider(){
document.querySelector("#arr_sz").disabled = false;
}
function disableNewArrayBtn(){
document.querySelector("#new-array").disabled = true;
}
function enableNewArrayBtn(){
document.querySelector("#new-array").disabled = false;
}