(examJson: Exam)
| 26 | * @returns An array of randomized questions for the exam. |
| 27 | */ |
| 28 | export function generateRandomExam(examJson: Exam): GeneratedExam { |
| 29 | const { numberOfQuestionsInExam, questions } = examJson; |
| 30 | const numberOfAnswersPerQuestion = 5; |
| 31 | |
| 32 | const availableQuestions = shuffleArray(filterDeprecated(questions)); |
| 33 | const examQuestions = availableQuestions.slice(0, numberOfQuestionsInExam); |
| 34 | |
| 35 | const randomizedExam: GeneratedExam = examQuestions.map( |
| 36 | (question: Question) => { |
| 37 | const availableCorrectAnswers = filterDeprecated(question.correctAnswers); |
| 38 | const availableWrongAnswers = shuffleArray( |
| 39 | filterDeprecated(question.wrongAnswers) |
| 40 | ); |
| 41 | const correctAnswer = getRandomElement(availableCorrectAnswers); |
| 42 | const answers = shuffleArray([ |
| 43 | correctAnswer, |
| 44 | ...availableWrongAnswers.slice(0, numberOfAnswersPerQuestion - 1) |
| 45 | ]).map(({ id, answer }) => ({ id, answer })); |
| 46 | return { |
| 47 | id: question.id, |
| 48 | question: question.question, |
| 49 | answers |
| 50 | }; |
| 51 | } |
| 52 | ); |
| 53 | |
| 54 | return randomizedExam; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Evaluates a user completed exam. |
no test coverage detected