vararr = [' AA ', 1.2, ' BB ', ' CC '];varLen =arr.length;//For (var i = 0; i < len; i++) {//The length of the alert (arr + "Array" is: "+ arr.length +" This time the first element of the team is: "+ arr.shift ());// }//alert ("Reflow array:" + arr.reverse ());//alert ("After array sorting:" + arr.sort ());vararr = [1, 4, 6, 9, 10, 21];//comparison numeric size of the primary versionfunctionComparebig (NUM1, num2) {if(Num1 <num2) { return-1; } Else if(NUM1 = =num2) { return0; } Else { return1; }}//the Gai method can be simplified when the two number is compared and can be converted to a numeric valuefunctionComparebigger (NUM1, num2) {returnNUM1-num2;}varStrarr = [' A ', ' aaaaa ', ' AA ', ' 124 ', ' 0SJSSD '];functionComparelen (str1, str2) {if(Str1.length <str2.length) {return-1; } Else if(Str1.length <str2.length) {return0; } Else { return1; }}alert (arr+ "sorted array is:" +Arr.sort (Comparebig)); Alert (Strarr+ "sorted array is:" + strarr.sort (Comparelen));
varArr=[' AA ', at,1.2,' BB ',' CC '];varLen=Arr.length;//For (var i = 0; i < len; i++) {//Alert (arr + "array length is:" + arr.length + "This time the first element of the team is:" + arr.shift ());// }//Alert ("After re-array:" + arr.reverse ());//Alert ("After array sorting:" + arr.sort ());varArr=[1,4,6,9,Ten, +];
//Primary version comparison numeric sizefunction Comparebig(NUM1,num2) {if(NUM1<NUM2) {return -1; }Else if(NUM1==NUM2) {return 0; }Else{return 1; }}
the Gai method can be simplified when the two number is compared and can be converted to a numeric value .function Comparebigger(NUM1,num2) {returnNum1-num2;}
varStrarr=[' A ',' AAAAA ',' AA ',' 124 ',' 0SJSSD '];
function Comparelen(str1,str2) {if(Str1.length<Str2.length) {return -1; }Else if(Str1.length<Str2.length) {return 0; }Else{return 1; }}Alert(arr+ "The sorted array is:" +Arr.Sort(Comparebig));Alert(Strarr+ "The sorted array is:" +Strarr.Sort(Comparelen));
Comparison functions in custom sort in JavaScript for comparing string lengths, numeric sizes