Codevar arrA = [6,2,4,3,5,1]; /**//*arrA.sort(); document.writeln(arrA); */ function desc(x,y) ...{ if (x > y) return -1; if (x < y) return 1; } function asc(x,y) ...{ if (x > y) return 1; if (x < y) return -1; } arrA.sort(desc); // sort by desc document.writeln(arrA); document.writeln("<br>"); arrA.sort(asc); //sort by asc document.writeln(arrA);
转载于:https://www.cnblogs.com/rabbit25132008/archive/2011/01/20/1940524.html