const [matchSummary, setMatchSummary] = useState(null);
const findWinner = () => {
const sortedPlayers = [...player].sort(
(a, b) => b.currentDistance - a.currentDistance
);
const summary = sortedPlayers.map((p, index) => {
const position = index + 1;
return `${position}${
position === 1 ? "st" : position === 2 ? "nd" : "rd"
} Position: Player ${index + 1}, Distance: ${
p.currentDistance
}, No of Turns: ${p.turnNumber}`;
});
const matchSummaryText = ["Match Summary", ...summary].join("\n");
setMatchSummary(matchSummaryText);
};