| 31 | |
| 32 | // Promise to swap two blocks |
| 33 | function swap(el1, el2) { |
| 34 | return new Promise((resolve) => { |
| 35 | |
| 36 | // For exchanging styles of two blocks |
| 37 | var temp = el1.style.transform; |
| 38 | el1.style.transform = el2.style.transform; |
| 39 | el2.style.transform = temp; |
| 40 | |
| 41 | window.requestAnimationFrame(function() { |
| 42 | |
| 43 | // For waiting for .25 sec |
| 44 | setTimeout(() => { |
| 45 | container.insertBefore(el2, el1); |
| 46 | resolve(); |
| 47 | }, 250); |
| 48 | }); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | // Asynchronous BubbleSort function |
| 53 | async function BubbleSort(delay = 100) { |