用apply求数组元素的最大值 最小值
<script>
// 用apply 借调求数组中的最大值或最小值
// 如果一个数组我们已知里面全都是数字,想要知道最大的那个数,由于 Array 没有 max 方法,Math 对象上有
// 我们可以根据 apply 传递参数的特性将这个数组当成参数传入
// 最终 Math.max 函数调用的时候会将 apply 的数组里面的参数一个一个传入,恰好符合 Math.max 的参数传递方式
// 这样变相的实现了数组的 max 方法。min 方法也同理
let newArr = [12, 5, 6, 3, 4]
let min = Math.min.apply(this, newArr) //求最大值
let max = Math.max.apply(this, newArr) //求最小值
console.log(min); //3 最小值
console.log(max); //12 最大值
</script>