CSR-108: minor refactoring

This commit is contained in:
Adam Caouette 2022-08-08 21:06:38 -04:00
parent af9d10d630
commit d4e87f7263

View file

@ -285,12 +285,13 @@ export default {
// suppress current question // suppress current question
thisAnsweredPartQuestion.suppressQuestion = true; thisAnsweredPartQuestion.suppressQuestion = true;
if (this.foundDuplicateQuestions["glassPart" + i]) { const thisGlassPart = "glassPart" + i;
if (!this.foundDuplicateQuestions["glassPart" + i].includes(thisAnsweredPartQuestion.questionSequence)) { if (this.foundDuplicateQuestions[thisGlassPart]) {
this.foundDuplicateQuestions["glassPart" + i].push(thisAnsweredPartQuestion.questionSequence); if (!this.foundDuplicateQuestions[thisGlassPart].includes(thisAnsweredPartQuestion.questionSequence)) {
this.foundDuplicateQuestions[thisGlassPart].push(thisAnsweredPartQuestion.questionSequence);
} }
} else { } else {
this.foundDuplicateQuestions["glassPart" + i] = [thisAnsweredPartQuestion.questionSequence]; this.foundDuplicateQuestions[thisGlassPart] = [thisAnsweredPartQuestion.questionSequence];
} }
// are there any questions left that are not suppressed? // are there any questions left that are not suppressed?
@ -338,7 +339,7 @@ export default {
// "glassPart2": [7, 10] // "glassPart2": [7, 10]
// }; // };
const thisPartsDupes = this.foundDuplicateQuestions['glassPart' + answer.partIndex]; const thisPartsDupes = this.foundDuplicateQuestions["glassPart" + answer.partIndex];
thisPartsDupes?.forEach((dupe) => { thisPartsDupes?.forEach((dupe) => {
// dupe is a single integer // dupe is a single integer
@ -373,10 +374,10 @@ export default {
}); });
// make sure there are no duplicated dupes... // make sure there are no duplicated dupes...
const seen = new Set(); const foundInCompleteAnsweredQuestions = new Set();
let filteredCompleteAnsweredQuestions = completeAnsweredQuestions.filter(el => { let filteredCompleteAnsweredQuestions = completeAnsweredQuestions.filter(el => {
const duplicate = seen.has(el.questionText); const duplicate = foundInCompleteAnsweredQuestions.has(el.questionText);
seen.add(el.questionText); foundInCompleteAnsweredQuestions.add(el.questionText);
return !duplicate; return !duplicate;
}); });
filteredCompleteAnsweredQuestions = filteredCompleteAnsweredQuestions.sort((a,b) => a.questionNum - b.questionNum); filteredCompleteAnsweredQuestions = filteredCompleteAnsweredQuestions.sort((a,b) => a.questionNum - b.questionNum);