Created
July 9, 2019 10:42
-
-
Save YuraKolesnikov/447cc524b27de6e80b9866d2f3ea4adc to your computer and use it in GitHub Desktop.
Working with array
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