Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created October 1, 2021 09:54
Show Gist options
  • Save paulobunga/6241f1bbaa670f007bce50714c53bcb6 to your computer and use it in GitHub Desktop.
Save paulobunga/6241f1bbaa670f007bce50714c53bcb6 to your computer and use it in GitHub Desktop.
Random Max Number Pseudocode
let array = [];
const generateNumberInRange = (min, max) => {
let number = Math.floor(Math.random() * (max - min + 1)) + min;
return number;
}
//Generate the random array to work with
Array.from({ length: 10000}).map((v, i) => {
let number = generateNumberInRange(1, 10000);
//Only push unique values to the array
if(array.indexOf(number) === -1) {
array.push(number);
}
});
console.log('***************************');
console.log('RANDOM ARRAY');
console.log(array);
console.log('***************************');
let maxNumber = 0;
for (let index = 0; index < array.length; index++) {
if(array[index] >= maxNumber) {
maxNumber = array[index];
console.log('Max Number is',maxNumber);
}
}
console.log(maxNumber)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment