Created
July 3, 2019 13:39
-
-
Save k0d3d/33aeffc8a34941a6385e6e3473d4eea0 to your computer and use it in GitHub Desktop.
Average and Sort
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
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) |
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
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