Skip to content

Commit 9712cb1

Browse files
committed
randomize candidates
1 parent f0f91c3 commit 9712cb1

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

client/app/components/vote/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ import {
1313
usePositions,
1414
useResults,
1515
useWS,
16+
type Candidate,
1617
} from "./queries";
1718
import { Button } from "../ui/button";
1819
import { Logo } from "../ui/logo";
1920
import { Link } from "react-router";
2021
import { useTheme } from "../theme-provider";
2122

23+
function randomize(array: Candidate[]) {
24+
for (let i = array.length - 1; i > 0; i--) {
25+
const j = Math.floor(Math.random() * (i + 1));
26+
[array[i], array[j]] = [array[j], array[i]];
27+
}
28+
}
29+
2230
const Vote = ({ logout }: { logout: () => void }) => {
2331
const { setTheme, theme } = useTheme();
2432
const isDarkMode = theme === "dark";
@@ -34,6 +42,8 @@ const Vote = ({ logout }: { logout: () => void }) => {
3442
if (wsData?.status === "finished") refetchElected();
3543
}, [wsData?.status]);
3644

45+
randomize(candidates);
46+
3747
return (
3848
<>
3949
<header className="flex justify-between py-1 px-4">

0 commit comments

Comments
 (0)