Created
October 1, 2021 09:54
-
-
Save paulobunga/6241f1bbaa670f007bce50714c53bcb6 to your computer and use it in GitHub Desktop.
Random Max Number Pseudocode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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