Last active
January 30, 2018 13:44
-
-
Save lestoni/9b3ca3ab1fb58b9f1a36ccd00bf13989 to your computer and use it in GitHub Desktop.
Ranking sorting and Average
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
// 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