JavaScript字符串数组排序

首发:http://windcoder.com/javascriptzifuchuanshuzupaixu/

代码:

                   var arry=["STEWARTS RT BEER 6/4/12 NR","7-UP 4/6/8 CN","",
						"1217-UP TEN 2/12 CN","DIET 7-UP 4/6/8 CN", 
						"1a1","FIJI 2/4/16.9 PET","",
						"1717A","1717","1717B","1716",
						"1716A","ABC","ABD","ACD","A123","A12D3","BCD","A123D",
						"FIJI 6/6/300 ML","FIJI 24/16.9 PET",
						"7-UP TEN 2/12 CN","217-UP TEN 2/12 CN"];
			var blnCheck = false;
			var i = arry.length,j;		
			while(i>0){	
					for(j=0;j57)
									&&(48<=arry[j+1][k].charCodeAt()&&arry[j+1][k].charCodeAt()<=57)){							
											break;
								}
								//若arry[j][K]为数字,j+1不为数字 交换顺序
								/*若arry[j][K]为数字,j+1为数字
								 *或arry[j][K]不为数字,i+1不为数字
								 * j>j+1 交换并跳出  j57)){
									blnCheck = true;                     	
									break;
								}else if(
									((48<=arry[j][k].charCodeAt()&&arry[j][k].charCodeAt()<=57)
										&&(48<=arry[j+1][k].charCodeAt()&&arry[j+1][k].charCodeAt()<=57))
									||((arry[j][k].charCodeAt()<48||arry[j][k].charCodeAt()>57)
										&&(arry[j+1][k].charCodeAt()<48||arry[j+1][k].charCodeAt()>57))){
									 if(arry[j][k]arry[j+1][k]){
										blnCheck = true;
										break;							 
									 }else  if((k==tmpLen-1&&arry[j][k]==arry[j+1][k])&&(arry[j].length>tmpLen)){
										blnCheck = true;
										break;
									 }		 
								} 								
							}
						}																		
						if (blnCheck) {
							tempExchangVal = arry[j];
							arry[j] = arry[j + 1];
							arry[j + 1] = tempExchangVal;
						}
						blnCheck = false;
					}					
					i--;
				}	 
			arry.forEach(function(e){
				document.write("
"+e+"
"); });



效果:






ABC

ABD

ACD

A12D3

A123

A123D

BCD

DIET 7-UP 4/6/8 CN

FIJI 2/4/16.9 PET

FIJI 24/16.9 PET

FIJI 6/6/300 ML

STEWARTS RT BEER 6/4/12 NR

1a1

1217-UP TEN 2/12 CN

1716

1716A

1717

1717A

1717B

217-UP TEN 2/12 CN

7-UP TEN 2/12 CN

7-UP 4/6/8 CN

你可能感兴趣的:(Web)