简单的纯数数组取极值(最大值和最小值)

今天举个简单的例子:

项目中遇到已知是纯number类型的数组,需要取该数组的极值,

ES5:

let Array = [-0.1,0,19,23,66.1,1,5,7,99,0,23,1,55],
tempMax = Math.max.apply(Math, Array)

tempMin = Math.min.apply(Math, Array)

// 99

// -0.1



ES6:

let Array = [-0.1,0,19,23,66.1,1,5,7,99,0,23,1,55],

tempMax = Math.max(... Array)

tempMin = Math.min(... Array)

// 99
//-0.1

^_^

猜你喜欢

转载自blog.csdn.net/heyNewbie/article/details/106551404