问答详情
源自:7-22 数组排序sort()

return b-a;//这里写成b-a,与-1,有什么区别吗?

<script type="text/javascript">

   function sortNum(a,b) {

     return b-a;//这里写成b-a,与-1,有什么区别吗?

   }

var myarr = new Array("80","16","50","6","100","1");

document.write(myarr.sort(sortNum));


提问者:慕容8154426 2017-10-02 10:13

个回答

  • 猿七
    2017-10-02 10:16:45

    a-b是升序,b-a是降序