fix: address code review issues in interactive exercises
- ExerciseSort: replace unbounded shuffle recursion with deterministic swap - ExerciseManager: add sortQuestion field so sort exercises have custom questions - index.vue: use Promise.allSettled so exercise fetch failure doesn't break lesson content - ExerciseManager: guard mcqAnswer index after option deletion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,8 @@ function shuffle(arr: LineItem[]): LineItem[] {
|
||||
;[a[i], a[j]] = [a[j], a[i]]
|
||||
}
|
||||
const isCorrect = a.every((item, i) => item.originalIdx === i)
|
||||
return isCorrect && a.length > 1 ? shuffle(arr) : a
|
||||
if (isCorrect && a.length > 1) [a[0], a[1]] = [a[1], a[0]]
|
||||
return a
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
@@ -147,9 +147,9 @@ async function init() {
|
||||
titles.value = res1.data
|
||||
if (titles.value.length === 0) return
|
||||
const id = titles.value[step.value - 1].id
|
||||
const [res2, exs] = await Promise.all([getTutorial(id), getExercises(id)])
|
||||
tutorial.value = res2.data
|
||||
exercises.value = exs
|
||||
const [res2, exs] = await Promise.allSettled([getTutorial(id), getExercises(id)])
|
||||
if (res2.status === "fulfilled") tutorial.value = res2.value.data
|
||||
exercises.value = exs.status === "fulfilled" ? exs.value : []
|
||||
}
|
||||
|
||||
watch(
|
||||
|
||||
Reference in New Issue
Block a user