const arr = [1, 5, 3, 7, 9, 21, 33, 18, 12, 44, 43, 22, 55, 66, 65]
const result = arr => {
// 存储最小值
let minMax = 0
// 存储最大值
let max = 0
arr.forEach(item => {
if (item > max) {
if (minMax < max) {
minMax = max
}
max = item
} else if (item > minMax) {
minMax = item
}
})
return [minMax, max]
}
console.log(result(arr))
标签:arr,const,max,最大值,js,item,查找,minMax From: https://www.cnblogs.com/-liujia/p/17408605.html