I am currently working on a project sorting visualizer and I need help for the array generation like in the given picture. please help me
Asked
Active
Viewed 142 times
4
-
Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour), visit the [help center](https://stackoverflow.com/help), and read up on [asking good questions](https://stackoverflow.com/help/asking). After doing some research and [searching](https://stackoverflow.com/help/searching) for related topics on SO, try it yourself. If you're stuck, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt note exactly where you're stuck. People will be glad to help. – Scott Sauyet Dec 21 '20 at 14:54
-
simple but interesting – tree Dec 21 '20 at 19:47
1 Answers
2
This functions will generate for you an array of random length with random number (with the ranges you determine), you can use it in your visualizer.
function createRandomSizeArray(minArrayLength, maxArrayLength, minColumnHeight, maxColumnHeight){
let ArrayLength = getRandomInt(minArrayLength, maxArrayLength);
let arr = new Array(ArrayLength);
for(let i = 0; i< arr.length; i++){
arr[i] = getRandomInt(minColumnHeight, maxColumnHeight);
}
return arr;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(createRandomSizeArray(5, 10, 2, 100));

Ran Marciano
- 1,431
- 5
- 13
- 30