方法1:直接利用Math的max方法
Math.max(10,20,30,40) // 40
方法2:自己写
// 不考虑都是负数的情况
function max(){
const nums = Array.prototype.slice.call(arguments) //把参数集合变为数组方便遍历
let max = 0
nums.forEach(n => {
if(n > max){
max = n
}
})
return max
}
网友评论