Created
July 9, 2019 10:41
-
-
Save YuraKolesnikov/26a60bd162a3dbc94a01283b7c0e6a4d to your computer and use it in GitHub Desktop.
array.js
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 array = [ | |
{ name: 'Alfred', ranking: 3 }, | |
{ name: 'Boris', ranking: 5 }, | |
{ name: 'Chris', ranking: 2 }, | |
{ name: 'Dylan', ranking: 1 }, | |
{ name: 'Fitzgerald', ranking: 4 } | |
] | |
const sortByRanking = () => array.sort((a, b) => a.ranking > b.ranking) | |
const findAvgRanking = () => (array.reduce((acc, curr) => acc + curr.ranking, 0)) / array.length | |
console.log(sortByRanking()) | |
console.log(findAvgRanking()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment