JavaScript 给定一个含有n个元素的整型数组a,打印其中的最大值和最小值.
var arr1 = [1, 2, 5, 3, 4, 8]
function fn(arr1) {
var max = arr1[0]
min = arr1[0]
for (var i in arr1) {
if (arr1[i] > max) {
max = arr1[i]
}
if (arr1[i] < min) {
min = arr1[i]
}
}
console.log('最大值为;' + max);
console.log('最小值为;' + min);
}
fn(arr1)