-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble.js
32 lines (31 loc) · 1.09 KB
/
bubble.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
async function bubble() {
console.log('In bubbe()');
const ele = document.querySelectorAll(".bar");
for(let i = 0; i < ele.length-1; i++){
console.log('In ith loop');
for(let j = 0; j < ele.length-i-1; j++){
console.log('In jth loop');
ele[j].style.background = 'blue';
ele[j+1].style.background = 'blue';
if(parseInt(ele[j].style.height) > parseInt(ele[j+1].style.height)){
console.log('In if condition');
await waitforme(delay);
swap(ele[j], ele[j+1]);
}
ele[j].style.background = 'cyan';
ele[j+1].style.background = 'cyan';
}
ele[ele.length-1-i].style.background = 'green';
}
ele[0].style.background = 'green';
}
const bubSortbtn = document.querySelector(".bubbleSort");
bubSortbtn.addEventListener('click', async function(){
disableSortingBtn();
disableSizeSlider();
disableNewArrayBtn();
await bubble();
enableSortingBtn();
enableSizeSlider();
enableNewArrayBtn();
});