forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

answer-sheet.ts16 lines, 641 bytesHistoryRawDownload
1import type { ExamQuestion, StudentAnswer } from "@/api/client";
2
3export type AnswerSheetRow = {
4 question: ExamQuestion;
5 answer: StudentAnswer | null;
6};
7
8/** Pair the exam's questions with a student's answers (`answer.question` → `question.id`).
9 * Unanswered questions get `answer: null`; answers to deleted questions are dropped. */
10export function joinAnswerSheet(questions: ExamQuestion[], answers: StudentAnswer[]): AnswerSheetRow[] {
11 const byQuestion = new Map(answers.map((answer) => [answer.question, answer]));
12 return questions.map((question) => ({
13 question,
14 answer: byQuestion.get(question.id) ?? null,
15 }));
16}