Skip to content

Instantly share code, notes, and snippets.

@arunkumar413
Created August 30, 2018 16:16
Show Gist options
  • Save arunkumar413/a2bd38f2cecb8ae596d5561175b0832d to your computer and use it in GitHub Desktop.
Save arunkumar413/a2bd38f2cecb8ae596d5561175b0832d to your computer and use it in GitHub Desktop.
return the objects ordered by ranking and another to return the average ranking.
var a = [{name:'john',rank:10},{name:"Alex",rank:5}];
var avg_rank=0;
ordered_array = order_rank(a);
console.log(ordered_array);
avg = find_avg(a);
console.log(avg);
function order_rank(a){
b = a.sort(function(x,y) { return x.rank - y.rank; })
return b;
}
function find_avg(a){
for (i=0;i<a.length;i++){
total = avg_rank+a[i].rank;
}
return(total/a.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment