hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import type { ExamQuestion, StudentAnswer } from "@/api/client"; |
| 2 | |
| 3 | export 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. */ |
| 10 | export 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 | } |