var arr = ["国","处","科","处","科","处","科","部","国","司","处","部","国","部","司","处","司","处","司","处","科"];
function arrSort(a,b){
if( (a=="国" && ( b=="部" || b=="司" || b=="处" || b=="科")) ||
(a=='部' && ( b=='司' || b=='处' || b=='科') ) ||
(a=='司' && ( b=='处' || b=='科')) ||
(a=='处' && b=='科' ) ){
return -1;
}
if(a == b){
return 0;
}
}
document.write(arr.sort(arrSort));
不太明白你的意思
已解决,我没考虑到的是,三种返回值都必须写出来,不然返回1时,是不会有效果。
正确解法:
在else中加入返回值,记住在这种类型中自定义排序方法中三种返回值都要写出来