search

Home  >  Q&A  >  body text

javascript - Use js to write a function that does not limit the number of parameters and is required to return the maximum value among all parameters

Write a function in js, without limiting the number of parameters, and return the maximum value of all parameters

天蓬老师天蓬老师2748 days ago848

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-19 10:29:56

    function maxNum(){return Math.max.apply(null,arguments)}

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:29:56

    function maxNum(...args){
        return Math.max(...args)
    }
    
    maxNum(0,1,2,3,4,5,6,7,8,9);    //9

    reply
    0
  • Cancelreply