Advertisement

中文汉字拼音排序(SPC), 通讯录排序, 中英混排

阅读量:

中文汉字按拼音排序,通讯录排序,中英混杂排序

直接展示代码内容

复制代码
    const sorter = (strA, strB) => {
    const reg = /^[a-zA-Z0-9]/; // 是否純数字或純英文
    if (reg.test(strA) || reg.test(strB)) {
    	    if (strA > strB) {
    	        return 1;
    	    } else if (strA < strB) {
    	        return -1;
    	    } else {
    	        return 0;
    	    }
    	}
    	// 中文排序
    	return strA.localeCompare(strB, 'zh', {
    	    numeric: true,
    	});
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    

全部评论 (0)

还没有任何评论哟~