fix: deduplicate distractors against each other, guard thin distractor pool

This commit is contained in:
lila 2026-04-28 15:44:29 +02:00
parent a02f3b139d
commit a02d3b3335
4 changed files with 68 additions and 370 deletions

View file

@ -42,9 +42,16 @@ export const createGameSession = async (
6,
);
const uniqueDistractors = distractorTexts.filter(
(t) => t !== term.targetText,
);
const uniqueDistractors = [
...new Set(distractorTexts.filter((t) => t !== term.targetText)),
];
if (uniqueDistractors.length < 3) {
throw new Error(
`Not enough unique distractors for term: ${term.targetText}`,
);
}
const optionTexts = [term.targetText, ...uniqueDistractors.slice(0, 3)];
const shuffledTexts = shuffleArray(optionTexts);
const correctOptionId = shuffledTexts.indexOf(term.targetText);