(delay = 300)
| 30 | |
| 31 | // Asynchronous LinearSearch function |
| 32 | async function LinearSearch(delay = 300) { |
| 33 | var blocks = document.querySelectorAll(".block"); |
| 34 | var output = document.getElementById("text"); |
| 35 | |
| 36 | //Extracting the value entered by the user |
| 37 | var num = document.getElementById("fname").value; |
| 38 | |
| 39 | //Changing the color of all the blocks to voilet |
| 40 | for (var i = 0; i < blocks.length; i += 1) { |
| 41 | blocks[i].style.backgroundColor = "#00ccff"; |
| 42 | } |
| 43 | |
| 44 | output.innerText = ""; |
| 45 | |
| 46 | var flag = 0; |
| 47 | // LinearSearch Algorithum |
| 48 | for (var i = 0; i < blocks.length; i += 1) { |
| 49 | //Changing the color of current block to red |
| 50 | blocks[i].style.backgroundColor = "#FF4949"; |
| 51 | |
| 52 | // To wait for .1 sec |
| 53 | await new Promise((resolve) => |
| 54 | setTimeout(() => { |
| 55 | resolve(); |
| 56 | }, delay) |
| 57 | ); |
| 58 | |
| 59 | //Extracting the value of current block |
| 60 | var value = Number(blocks[i].childNodes[0].innerHTML); |
| 61 | |
| 62 | // To compare block value with entered value |
| 63 | if (value == num) { |
| 64 | flag = 1; |
| 65 | output.innerText = "Element Found"; |
| 66 | blocks[i].style.backgroundColor = "#13CE66"; |
| 67 | break; |
| 68 | } else { |
| 69 | // Changing the color to the previous one |
| 70 | blocks[i].style.backgroundColor = "#00ccff"; |
| 71 | } |
| 72 | } |
| 73 | //When element is not found in the array |
| 74 | if (flag == 0) { |
| 75 | output.innerText = "Element Not Found"; |
| 76 | } |
| 77 | // To enable the button "Generate New Array" after final(sorted) |
| 78 | document.getElementById("Button1").disabled = false; |
| 79 | document.getElementById("Button1").style.backgroundColor = "#6f459e"; |
| 80 | |
| 81 | // To enable the button "Linear Search" after final(sorted) |
| 82 | document.getElementById("Button2").disabled = false; |
| 83 | document.getElementById("Button2").style.backgroundColor = "#6f459e"; |
| 84 | } |
| 85 | |
| 86 | // Calling generatearray function |
| 87 | generatearray(); |
nothing calls this directly
no outgoing calls
no test coverage detected