Skip to main content

Command Palette

Search for a command to run...

JavaScript - Min and Max values from an Array of Numbers

Published
1 min read
JavaScript - Min and Max values from an Array of Numbers
D

I'm a Software Engineer with 9+ years of experience. I've extensive knowledge of different technologies and programming languages. I've skills in Web Development, Databases, and Agile Methodologies. I'm constantly looking to explore new technologies and new opportunities to learn.

You have an array of numbers and you need to know the minimum and maximum values of the array without having to traverse the entire array, don't worry about it, you can get the minimum and maximum values very quickly using the following expression:

let values = [200, 0, 1, 24, -5, 10]
const minValue  = Math.min(...values)
const maxValue = Math.max(...values) 
console.log(minValue, maxValue)

// Output --> -5 200

Screen Recording 2022-10-14 at 01.04.33.gif

Do you know another way to do that? Please if so let me know in the comments below. ✌️😎