Why Math.min() > Math.max()?

前端 未结 10 619
暖寄归人
暖寄归人 2020-12-24 12:58

When I type in an array into the parameter of the javascript math minimum and maximum functions, it returns the correct value:

console.log( Math.min( 5 ) );         


        
10条回答
  •  难免孤独
    2020-12-24 13:16

    The idea is, mathematically without any parameter you actually have an undefined value for the minimum.

    As for implementation wise, usually the min value is initialized with a very large value(Infinity), which is then updated as smaller values are found. If no value is found, then you have Infinity as the min value.

    The case is opposite with finding the maximum value and that is why you have -Infinity .

提交回复
热议问题