30 lines
582 B
TypeScript
30 lines
582 B
TypeScript
const correctAnswers: Record<number, string> = {
|
|
1: 'B',
|
|
2: 'A',
|
|
3: 'B',
|
|
4: 'A',
|
|
5: 'B',
|
|
6: 'B',
|
|
7: 'B',
|
|
};
|
|
|
|
export function calculateCRTResults(answers: string[]) {
|
|
const items = answers.map((answer, index) => {
|
|
const questionId = index + 1;
|
|
return {
|
|
questionId,
|
|
selected: answer,
|
|
correct: correctAnswers[questionId],
|
|
isCorrect: answer === correctAnswers[questionId],
|
|
};
|
|
});
|
|
|
|
const score = items.filter((item) => item.isCorrect).length;
|
|
|
|
return {
|
|
score,
|
|
total: Object.keys(correctAnswers).length,
|
|
items,
|
|
};
|
|
}
|