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); }
原文:https://www.cnblogs.com/Super-Zhen-/p/9175647.html