js找出列表中最大/最小元素

根据MDN官方的定义:可以使用reduce:

const a = Array(100).fill(Math.random());

let max = a.reduce( (a,b)=>{ return Math.max(a,b)})

或者使用速度更快的一种方法:

let max =  Math.max(...a)

但是由于max函数参数的限制,这种方法中a列表的元素个数不能太多

posted @ 2021-10-17 23:34  Bravo_Jack  阅读(229)  评论(0编辑  收藏  举报