Maximum value in an array
Let's start with an array of numbers where we need to get the maximum value.
It doesn't really matter how we get those numbers into the array, all that matters is that we have an array and want to get the maximum value. To get the maximum value from the array we run the following code:
ary = [4,7,-2,55,2,12];
The variable max now contains the maximum value from the array called ary (if you run both these statements then max contains 55).
max = Math.max.apply(Math,ary);
To get the minimum value just substitute Math.min instead of Math.max
No loops and just a single call and we have the answer.