Find The Smallest or Highest Value of Array

Finding the smallest number or the highest one is common question that every coder will face. It was easy question. When using JavaScript, there are several method that can help.

For an example, we have an array like this

[34, -345, -1, 100]

As we know the smallest value is -345 and the highest one is 100. To get that value, easily we just need to sort them, so it become like this.

[-345, -1, 34, 100]

After that, we can get the smallest and the highest value by accessing the first index or last index. Or if you want to get shortest path, using the Math method .min() and .max() it will save your time a lot.

Here is my code:

Thanks!!!

--

--