From 955954e03b4f7a9caab382b4e63cc2293080fc5f Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 8 Jan 2026 02:37:06 +0100 Subject: [PATCH] Add shuffleQuestionOptions function to QuizRunner.tsx --- client/src/components/QuizRunner.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/src/components/QuizRunner.tsx b/client/src/components/QuizRunner.tsx index a502f8b..add67d4 100644 --- a/client/src/components/QuizRunner.tsx +++ b/client/src/components/QuizRunner.tsx @@ -28,6 +28,23 @@ function shuffle(list: T[]) { return copy; } +function shuffleQuestionOptions(question: QuizQuestionWithEntry): QuizQuestionWithEntry { + const payload = { ...(question.payload || {}) }; + const answer = { ...(question.answer || {}) }; + + if (Array.isArray(payload.options)) { + const optionsWithIndex = payload.options.map((opt: any, idx: number) => ({ opt, idx })); + const shuffled = shuffle(optionsWithIndex); + payload.options = shuffled.map((p) => p.opt); + if (typeof answer.correct_index === 'number') { + const newIdx = shuffled.findIndex((p) => p.idx === answer.correct_index); + answer.correct_index = newIdx >= 0 ? newIdx : answer.correct_index; + } + } + + return { ...question, payload, answer }; +} + const normalize = (val: any) => (val === undefined || val === null ? '' : String(val).trim()); function resolveTargets(question: QuizQuestionWithEntry): TargetHit[] {