Created
January 9, 2017 16:41
-
-
Save saginadir/b542b67b29a65f36112875deec5dee02 to your computer and use it in GitHub Desktop.
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 players = {itamar: 1200, eddie: 1210, eli: 1183, uriel: 1201}; | |
const sortedPlayers = | |
Object.keys(players) // Convert all object keys to an array | |
.map(p => ({name: p, rank: players[p]})) // Map to wanted object | |
.sort(function(a, b) { // Sort! | |
return b.rank - a.rank; | |
}); | |
console.log(sortedPlayers); // Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment