js 首先通过成绩从小到大进行排序,成绩相同者通过学号从大到小进行排序
function sort(arr,attr,attr2){
var len=arr.length;
if(len<=1){
return arr;
}
var num=Math.floor(len/2);
var numVal=arr[num][attr];
var numVal2=arr[num][attr2];
var numStu=arr.splice(num,1);
var left=[],right=[];
for(var i=0;i<len-1;i++){
if(arr[i][attr]<numVal){
left.push(arr[i]);
}else if(arr[i][attr]==numVal){
if(arr[i][attr2]>numVal2){left.push(arr[i])}else{right.push(arr[i])}
}else{right.push(arr[i]);}
}
return sort(left,attr,attr2).concat(numStu,sort(right,attr,attr2));
}
var students=[
{num:20112110,name:'11',goal:80},
{num:20112100,name:'aa',goal:40},
{num:20112112,name:'vv',goal:87},
{num:20112116,name:'dd',goal:54},
{num:20112108,name:'cc',goal:22},
{num:20112134,name:'44',goal:80},
{num:20112117,name:'11',goal:80},
{num:20112109,name:'aa',goal:40},
{num:20112113,name:'vv',goal:87},
{num:20112135,name:'dd',goal:54},
{num:20112102,name:'cc',goal:22},
{num:20112111,name:'44',goal:80}
];
var sortByGoal=sort(students,'goal','num');