5-1reduce()归并求和
var arr=[1,2,3,4];
var sum=arr.reduce((a,b)=>{
return a+b;
})
console.log(sum);//10
console.log(arr);//[1,2,3,4]
5-2Math max()取最大值
var arr=[1,2,3];
console.log(Math.max(12,3,4));//12
console.log(Math.max(...arr));//要先展开数组,才可以找最大值 3
5-3Math.min()取最小值
var arr=[5,4,3,2];
console.log(Math.min(...arr));
//算法
var arr=[5,4,3,2];
var minNum=arr[0]
for(var i=1;i<arr.length;i++){
if(minNum>arr[i]){
minNum=arr[i]
}
}
console.log(minNum);