Created
August 30, 2018 16:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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