| 3 | |
| 4 | // Function to generate bars |
| 5 | function generatebars(num = 20) { |
| 6 | |
| 7 | //For loop to generate 20 bars |
| 8 | for (let i = 0; i < num; i += 1) { |
| 9 | |
| 10 | // To generate random values from 1 to 100 |
| 11 | const value = Math.floor(Math.random() * 100) + 1; |
| 12 | |
| 13 | // To create element "div" |
| 14 | const bar = document.createElement("div"); |
| 15 | |
| 16 | // To add class "bar" to "div" |
| 17 | bar.classList.add("bar"); |
| 18 | |
| 19 | // Provide height to the bar |
| 20 | bar.style.height = `${value * 3}px`; |
| 21 | // Translate the bar towards positive X axis |
| 22 | bar.style.transform = `translateX(${i * 30}px)`; |
| 23 | |
| 24 | // To create element "label" |
| 25 | const barLabel = document.createElement("label"); |
| 26 | |
| 27 | // To add class "bar_id" to "label" |
| 28 | barLabel.classList.add("bar__id"); |
| 29 | |
| 30 | // Assign value to "label" |
| 31 | barLabel.innerHTML = value; |
| 32 | |
| 33 | // Append "Label" to "div" |
| 34 | bar.appendChild(barLabel); |
| 35 | |
| 36 | // Append "div" to "data-container div" |
| 37 | container.appendChild(bar); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | // Asynchronous function to perform "Insertion Sort" |
| 42 | async function InsertionSort(delay = 600) { |