# Math.max 与 Math.min
# 简介
Math.max 返回参数中的最大值,Math.min 返回最小值。
# 定义
Math.max()返回-InfinityMath.min()返回Infinity- 任意参数为
NaN时,结果为NaN
# JS 实现
const max = (...args) => args.reduce((m, x) => (x > m ? x : m), -Infinity)
const min = (...args) => args.reduce((m, x) => (x < m ? x : m), Infinity)
# 例子
Math.max(1, 2, 3) // 3
Math.min(1, 2, 3) // 1
# 应用
常用于求极值、裁剪范围(clamp)、以及搜索空间的上下界。