-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (28 loc) · 698 Bytes
/
script.js
File metadata and controls
34 lines (28 loc) · 698 Bytes
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
const n=50;
const array = [];
init();
function showBars(move){
container.innerHTML="";
for(let i=0;i<array.length;i++){
//creating an bar:
const bar = document.createElement("div");
bar.style.height=array[i]*100+"%";
bar.classList.add("bar");
if(move && move.indices.includes(i)){
bar.style.backgroundColor=
move.type=="swap" ? "#bb87fd":"#8d0000";
}
container.appendChild(bar);
}
};
function init(){
for(i=0;i<n;i++){
array[i] = Math.random();
}
showBars();
}
function play(){
const copyArray = [...array];
const moves = bubbleSort(copyArray);
animate(moves);
}