From: Carl Worth Date: Thu, 18 Jun 2020 18:54:09 +0000 (-0700) Subject: Put commas back into players' overall scores list X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=13c7633c804d5d1e51f2af1083f96e20b784ecfb Put commas back into players' overall scores list I keep learning that the less logic there is in JSX, the better. --- 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 (
Players: - {sorted_players.map(player => ( - - {player.name} - {player.score > 0 ? ` (${player.score})` : ""} - {" "} - - ))} + {names_and_scores}
); });