MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / generatearray

Function generatearray

assets/js/ternarysearch.js:4–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3// Function to generate the array of blocks
4function generatearray() {
5
6 // Creating an array
7 var arr = [];
8
9 // Filling array with random values
10 for (var i = 0; i < 20; i++) {
11
12 // Return a value from 1 to 100 (both inclusive)
13 var val = Number(Math.ceil(Math.random() * 100));
14 arr.push(val);
15 }
16
17 // Sorting Array in ascending order
18 arr.sort(function(a, b) {
19 return a - b;
20 });
21
22 for (var i = 0; i < 20; i++) {
23 var value = arr[i];
24
25 // Creating element div
26 var array_ele = document.createElement("div");
27
28 // Adding class 'block' to div
29 array_ele.classList.add("block");
30
31 // Adding style to div
32 array_ele.style.height = `${value * 3}px`;
33 array_ele.style.transform = `translate(${i * 30}px)`;
34
35 // Creating label element for displaying
36 // size of particular block
37 var array_ele_label = document.createElement("label");
38 array_ele_label.classList.add("block_id");
39 array_ele_label.innerText = value;
40
41 // Appending created elements to index.html
42 array_ele.appendChild(array_ele_label);
43 container.appendChild(array_ele);
44 }
45}
46
47// Asynchronous TernarySearch function
48async function TernarySearch(delay = 700) {

Callers 1

ternarysearch.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected