Math.min.apply(0, array) - why?

后端 未结 4 1143
情话喂你
情话喂你 2020-12-13 13:31

I was just digging through some JavaScript code (Raphaël.js) and came across the following line (translated slightly):

Math.min.apply(0, x)

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 13:40

    Here is an example where we can get the MAX and MIN timezone offsets for the given year for a timezone. It returns the two changes for the year to account for DST and ST. (i.e. ST = 300 an DST = 360 for the timezone in question).

       var arr = [];
       for (var i = 0; i < 365; i++) {
           var d = new Date();
           d.setDate(i);
           var newoffset = d.getTimezoneOffset();
           arr.push(newoffset);
       }
       var DST = Math.min.apply(null, arr);
       var nonDST = Math.max.apply(null, arr);
       tw.local.stInt = DST
       tw.local.edInt = nonDST
    

提交回复
热议问题