Skip to content

Instantly share code, notes, and snippets.

@gbols
Created October 20, 2019 07:41
Show Gist options
  • Save gbols/ff05850a222d7b4d675ff538ca94afdb to your computer and use it in GitHub Desktop.
Save gbols/ff05850a222d7b4d675ff538ca94afdb to your computer and use it in GitHub Desktop.
const users = [
{
name: "matt sanders",
rank: 5
},
{
name: "winifred bony",
rank: 2
},
{
name: "gbolahan olagunju",
rank: 1
}
]
const sortedbyRank = users.sort((a, b) => b.rank < a.rank);
console.log(sortedbyRank)
const averageRanking = (users) => {
const total = users.reduce((total, current) => total + current.rank, 0);
return total / users.length;
}
console.log(averageRanking(users));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment