fix: deduplicate distractors against each other, guard thin distractor pool
This commit is contained in:
parent
a02f3b139d
commit
a02d3b3335
4 changed files with 68 additions and 370 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue