29 lines
855 B
TypeScript
29 lines
855 B
TypeScript
import type { IPracticeCheck } from '@/types/practice.ts'
|
|
import type { IQuestion } from '@/types/question.ts'
|
|
|
|
export const isAnswerCorrect = (answer: string[], select: string[]): boolean => {
|
|
const normAnswer = Array.from(new Set(answer)).sort()
|
|
const normSelect = Array.from(new Set(select)).sort()
|
|
|
|
if (normAnswer.length !== normSelect.length) {
|
|
return false
|
|
}
|
|
|
|
return normAnswer.every((v, i) => v === normSelect[i])
|
|
}
|
|
|
|
export const optLetter = (index: number): string => {
|
|
return String.fromCharCode(65 + index)
|
|
}
|
|
|
|
export const getMistakeList = (questions: IQuestion[],
|
|
checks: IPracticeCheck[]): IQuestion[] => {
|
|
const checkMap = new Map<number, IPracticeCheck>()
|
|
checks.forEach((c) => checkMap.set(c.id, c))
|
|
|
|
return questions.filter((q) => {
|
|
const check = checkMap.get(q.id)
|
|
return !check || !check.isCorrect
|
|
})
|
|
}
|