Javascript Code Snippets - Number

Random number between

function getRandomNumber(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Example usage
const randomNumber = getRandomNumber(100, 500);
console.log(randomNumber);

Get the highest or lowest value in an array using Math.max and Math.min

const numbers = [2, 1, 10, 5, 8, 3, 9];
const highestValue = Math.max(...numbers);
const lowest = Math.min(...numbers);