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

前端 未结 10 592
暖寄归人
暖寄归人 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条回答
  •  萌比男神i
    2020-12-24 13:09

    It's the same reason why the sum of an empty list is usually defined as 0 and their product as 1: it is the identity element of the operation. That is, whenever you include -Infinity as an element when computing max, it does not affect the result; respectively for Infinity and min.

    This is sensible because it allows desirable "associative" properties for the aggregate operations. For example, the sum of a list is the same as computing the sums of any sublists (maybe including empty) and summing them. Likewise for products, mins, maxes and so on.

提交回复
热议问题