Fix a bug for matrix answers in surveys
The bug can appear if a question has inconsistent punctuation in the indexes of its rows compared to other surveys.
This commit is contained in:
parent
f201de2d46
commit
0e166a6b10
|
|
@ -3,15 +3,13 @@ const extractAnswerFromQuestion = (previous, question) => {
|
||||||
if (question.getType() === 'matrix') {
|
if (question.getType() === 'matrix') {
|
||||||
const correctAnswer = question.correctAnswer;
|
const correctAnswer = question.correctAnswer;
|
||||||
const questionRows = question.getRows();
|
const questionRows = question.getRows();
|
||||||
const keys = questionRows.map(question => {
|
const keys = questionRows.map(question => question.value); // get the keys as they appear in the question
|
||||||
const text = question.value;
|
|
||||||
if (/[,.!?]/.test(text.slice(-1))) {
|
|
||||||
return text.slice(0, -1);
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}); // get the keys as they appear in the question, without punctuation at the end
|
|
||||||
|
|
||||||
answer = keys.map(key => `${key}: ${correctAnswer[key]}`); // return an array, it gets converted to a string further up
|
answer = keys.map(key => {
|
||||||
|
let keyWithoutPunctuation = /[,.!?]/.test(key.slice(-1)) ? key.slice(0, -1) : key; // the last character might be a period, comma, question or exclamation mark. If not, we just return the key as-is
|
||||||
|
let answer = correctAnswer[key] || correctAnswer[keyWithoutPunctuation]; // the key might be with or without the punctuation, can be inconsistent depending on the survey
|
||||||
|
return `${keyWithoutPunctuation}: ${answer}`; // return the key without punctuation, as we add the colon
|
||||||
|
}); // return an array, it gets converted to a string further up
|
||||||
}
|
}
|
||||||
return [...previous, {title: question.title, answer, type: question.getType()}];
|
return [...previous, {title: question.title, answer, type: question.getType()}];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue