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

Function generatearray

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

Callers 1

binarysearch.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected