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