From 13c7633c804d5d1e51f2af1083f96e20b784ecfb Mon Sep 17 00:00:00 2001 From: Carl Worth <cworth@cworth.org> Date: Thu, 18 Jun 2020 11:54:09 -0700 Subject: [PATCH] Put commas back into players' overall scores list I keep learning that the less logic there is in JSX, the better. --- empathy/empathy.jsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 82bb5ff..0c1fccf 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -205,20 +205,23 @@ const PlayerInfo = React.memo(props => { if (! props.player.id) return null; - const sorted_players = [props.player, ...props.other_players].sort((a,b) => { + const all_players = [props.player, ...props.other_players]; + + const sorted_players = all_players.sort((a,b) => { return b.score - a.score; }); + const names_and_scores = sorted_players.map(player => { + if (player.score) + return `${player.name} (${player.score})`; + else + return player.name; + }).join(', '); + return ( <div className="player-info"> <span className="players-header">Players: </span> - {sorted_players.map(player => ( - <span key={player.id}> - {player.name} - {player.score > 0 ? ` (${player.score})` : ""} - {" "} - </span> - ))} + <span>{names_and_scores}</span> </div> ); }); -- 2.45.2