Add a space between multiple solutions for the same matrix row

This commit is contained in:
Ramon Wenger 2023-06-07 23:14:33 +02:00
parent 11ad61c355
commit 315d84316e
1 changed files with 1 additions and 16 deletions

View File

@ -16,36 +16,21 @@ const extractAnswerFromQuestion = (previous: any[], question: Question) => {
return [...previous]; return [...previous];
} }
let answer = question.correctAnswer; let answer = question.correctAnswer;
console.log(question.getType());
const type = question.getType(); const type = question.getType();
if (type === 'matrix' || type === 'matrixdropdown') { if (type === 'matrix' || type === 'matrixdropdown') {
const correctAnswer = question.correctAnswer; const correctAnswer = question.correctAnswer;
const { rows, columns } = question; const { rows, columns } = question;
console.log('columns', columns);
const col1 = columns[0]; const col1 = columns[0];
const col2 = columns[1]; const col2 = columns[1];
console.log('col1', col1);
console.log(col1.value);
console.log(col1.name);
console.log(col1.locTextValue);
console.log(col2);
console.log(col2.choices);
answer = rows.map(({ text, value }: RowKey) => { answer = rows.map(({ text, value }: RowKey) => {
const labelWitoutPunctuation = /[,.!?]/.test(text.slice(-1)) ? text.slice(0, -1) : text; // the last character might be a period, comma, question or exclamation mark. If not, we just return the key as-is const labelWitoutPunctuation = /[,.!?]/.test(text.slice(-1)) ? text.slice(0, -1) : text; // the last character might be a period, comma, question or exclamation mark. If not, we just return the key as-is
console.log('correctAnswer', correctAnswer);
let answer; let answer;
if (type === 'matrix') { if (type === 'matrix') {
answer = correctAnswer[value] || correctAnswer[labelWitoutPunctuation]; // the key might be with or without the punctuation, can be inconsistent depending on the survey answer = correctAnswer[value] || correctAnswer[labelWitoutPunctuation]; // the key might be with or without the punctuation, can be inconsistent depending on the survey
} else { } else {
const answers = correctAnswer[value] || correctAnswer[labelWitoutPunctuation]; // the key might be with or without the punctuation, can be inconsistent depending on the survey const answers = correctAnswer[value] || correctAnswer[labelWitoutPunctuation]; // the key might be with or without the punctuation, can be inconsistent depending on the survey
// console.log(answers); answer = Object.keys(answers).join(', ');
// console.log(answers.getOwnPropertyNames());
// const forcedObject = { ...answers };
// console.log(forcedObject.getOwnPropertyNames());
// console.log(forcedObject.keys());
// answer = answers.keys();
answer = Object.keys(answers);
console.log(answer); console.log(answer);
} }
return `${labelWitoutPunctuation}: ${answer}`; // return the key without punctuation, as we add the colon return `${labelWitoutPunctuation}: ${answer}`; // return the key without punctuation, as we add the colon