Skip to content

Commit

Permalink
fix: 選択肢シャッフル有効時でも正答が元のままだった
Browse files Browse the repository at this point in the history
  • Loading branch information
watasuke102 committed Feb 16, 2024
1 parent 99b9835 commit 544cc9f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app/exam/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export default async function Exam(props: Props): Promise<JSX.Element> {
.filter((_, i) => !((begin && i < begin) || (end && i > end)))
.map(e => {
if (props.searchParams.choiceShuffle && Array.isArray(e.question_choices)) {
e.question_choices = Shuffle(e.question_choices);
const choices = Shuffle(e.question_choices.map((e, i) => ({original_index: i, choice: e})));
e.question_choices = choices.map(choice => choice.choice);
if (e.type === 'Select' || e.type === 'MultiSelect') {
e.answer = choices.flatMap((choice, i) =>
e.answer.indexOf(String(choice.original_index)) !== -1 ? String(i) : [],
);
}
}
return e;
});
Expand Down

0 comments on commit 544cc9f

Please sign in to comment.