feat:更新训练场模块
This commit is contained in:
28
src/utils/practiceUtil.ts
Normal file
28
src/utils/practiceUtil.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user