Sort player list by overall scores
authorCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 16:14:25 +0000 (09:14 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 16:14:25 +0000 (09:14 -0700)
Making it that much easier to see who is in the lead

empathy/empathy.jsx

index e67bbc87afbc91941c7460bb52aeb865aeac0d5b..82bb5ff681989470aa2a78e10d9f7eedc5f42d51 100644 (file)
@@ -205,16 +205,18 @@ const PlayerInfo = React.memo(props => {
   if (! props.player.id)
     return null;
 
+  const sorted_players = [props.player, ...props.other_players].sort((a,b) => {
+    return b.score - a.score;
+  });
+
   return (
     <div className="player-info">
       <span className="players-header">Players: </span>
-      {props.player.name}
-      {props.player.score > 0 ? ` (${props.player.score})` : ""}
-      {props.other_players.map(other => (
-        <span key={other.id}>
-          {", "}
-          {other.name}
-          {other.score > 0 ? ` (${other.score})` : ""}
+      {sorted_players.map(player => (
+        <span key={player.id}>
+          {player.name}
+          {player.score > 0 ? ` (${player.score})` : ""}
+          {" "}
         </span>
       ))}
     </div>