数组排序 记录一下

var array2 = [1,20,3,4,7,8,5,3,1,2];
 var sortArray =  function (a,b){
     if(a>b){
         return 1;
     }else if(a<b){
         return -1
     }else{
         return 0;
     }
 }

{

        let array = [1,-100,20,10,0,12,9,8];
        function compare(val1,val2){
            return val1-val2;
        }
        array.sort(compare);
        console.log(array);
    }

猜你喜欢

转载自www.cnblogs.com/Super-Zhen-/p/9175647.html