Skip to content

Instantly share code, notes, and snippets.

@lestoni
Last active January 30, 2018 13:44
Show Gist options
  • Save lestoni/9b3ca3ab1fb58b9f1a36ccd00bf13989 to your computer and use it in GitHub Desktop.
Save lestoni/9b3ca3ab1fb58b9f1a36ccd00bf13989 to your computer and use it in GitHub Desktop.
Ranking sorting and Average
// Sort Arr by Ranking
function sortByRanking(arr) {
let compare = function (a,b) {
if (a.ranking < b.ranking) {
return -1;
} else if (a.ranking > b.ranking) {
return 1;
} else {
return 0;
}
};
return arr.sort(compare);
}
// Find Average of rankings
function averageRanking(arr) {
let totalValues = arr.length;
let sum = 0;
arr.forEach(function (obj) {
sum += +item.ranking;
});
return sum/totalValues;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment