The algorithm for finding the minimum value is as follows:

  1. Assign the first element of the array to a variable, and use this variable as the minimum value;
  2. Start traversing the array, comparing each element from the second element onward with the first element;
  3. If the current element is less than the current minimum, assign the current element value to the minimum;
  4. Move to the next element and continue with step three;
  5. When the array elements have been fully traversed, the value stored in this variable is the minimum value;

The code is as follows:

// 查找数组中最小值
function arrayMin(arrs){
    var min = arrs[0];
    for(var i = 1, ilen = arrs.length; i < ilen; i+=1) {
        if(arrs[i] < min) {
            min = arrs[i];
        }
    }
    return min;
}
// 代码测试
var rets = [2,4,5,6,7,9,10,15];
console.log(arrayMin(rets));//2

The above compares the numeric values in the array. If the numbers in the array are strings, you first need to convert the strings into numbers before comparing, because string comparison is not based on values but on ASCII codes. For example, the ASCII code of '2' is greater than the ASCII code of '15', because the first digit of the ASCII code for 15 is 1, and the ASCII code of 2 is definitely greater than 1;

The algorithm for finding the maximum value is similar to the above:

  1. Assign the first element of the array to a variable, and use this variable as the maximum value;
  2. Start traversing the array, comparing each element from the second element onward with the first element;
  3. If the current element is greater than the current maximum, assign the current element value to the maximum;
  4. Move to the next element and continue with step three;
  5. When the array elements have been fully traversed, the value stored in this variable is the minimum value;

The code is as follows:

// 在数组中查找最大值
function arrayMax(arrs) {
    var max = arrs[0];
    for(var i = 1,ilen = arrs.length; i < ilen; i++) {
        if(arrs[i] > max) {
            max = arrs[i];
        }
    }
    return max;
}
// 代码测试
var rets = [2,4,5,6,7,9,10,15];
console.log(arrayMax(rets));//15