Skip to content

Instantly share code, notes, and snippets.

@saginadir
Created January 9, 2017 16:41
Show Gist options
  • Save saginadir/b542b67b29a65f36112875deec5dee02 to your computer and use it in GitHub Desktop.
Save saginadir/b542b67b29a65f36112875deec5dee02 to your computer and use it in GitHub Desktop.
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