Skip to content

Instantly share code, notes, and snippets.

@k0d3d
Created July 3, 2019 13:39
Show Gist options
  • Save k0d3d/33aeffc8a34941a6385e6e3473d4eea0 to your computer and use it in GitHub Desktop.
Save k0d3d/33aeffc8a34941a6385e6e3473d4eea0 to your computer and use it in GitHub Desktop.
Average and Sort
const arr = [
{
"name": "Jeff",
"ranking": 1
},
{
"name": "Kevin",
"ranking": 5
},
{
"name": "Wanda",
"ranking": 9
},
{
"name": "Jerry",
"ranking": 2
}
]
const avg = arr.reduce((a, b) => a + b.ranking, 0) / arr.length
console.log(avg)
const arr = [
{
"name": "Jeff",
"ranking": 1
},
{
"name": "Kevin",
"ranking": 5
},
{
"name": "Wanda",
"ranking": 9
},
{
"name": "Jerry",
"ranking": 2
}
]
console.log(arr.sort((a, b) => a.ranking - b.ranking))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment