]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Sort player list by overall scores
[lmno.games] / empathy / empathy.jsx
index e67bbc87afbc91941c7460bb52aeb865aeac0d5b..82bb5ff681989470aa2a78e10d9f7eedc5f42d51 100644 (file)
@@ -205,16 +205,18 @@ const PlayerInfo = React.memo(props => {
   if (! props.player.id)
     return null;
 
   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>
   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>
         </span>
       ))}
     </div>