求数组总和,最大值,最小值

const arr = [4,5,6,7,8]
//求和
const sum = arr.reduce((a,b) => a+b) //30
//最小值
const min = arr.reduce((a,b) => a > b ? b : a) //4
//最大值
const max = arr.reduce((a,b) => a > b ? a : b) //8

  

posted @ 2022-02-08 11:12  是你吗我笑了  阅读(40)  评论(0)    收藏  举报