利用函数求任意个数的最大值

 

 

 

  <script>
    function getMax() {
      let max = arguments[0];
      for (let i = 0; i < arguments.length; i++) {
        if (arguments[i] > max) {
          max = arguments[i];
        }
      }
      return max;
    }
    console.log(getMax(5, 3, 4, 9));
    console.log(getMax(10, 15, 32, 15, 40));
    console.log(getMax(20, 45, 31, 60, 54));
  </script>

 

posted @ 2022-04-08 11:32  罗砂  阅读(120)  评论(0)    收藏  举报