-
Notifications
You must be signed in to change notification settings - Fork 74
(EAI-1257) handle multiple correct and more answer options #887
base: main
Are you sure you want to change the base?
Conversation
| const answers = ["A", "B", "C", "D", "E", "F"] | ||
| .map((label) => { | ||
| const isCorrect = correctAnswers.includes(label); | ||
| return { | ||
| answer: row[label], | ||
| isCorrect, | ||
| label, | ||
| }; | ||
| }) | ||
| .filter((answer) => answer.answer && answer.answer.trim() !== ""); // Remove empty answers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this code could be a little cleaner. rather than filtering at the end, can you slice the array of ["A", "B", "C", ...] to the correct length before running the map over it?
| const handleAnswers = (row: any) => { | ||
| const correctAnswers = row.Answer.trim()?.split("") || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing row: any, please make sure that the input is strongly typed. you can use zod to do any validation that you need.
| questionType: | ||
| row["Answer"].length > 1 ? "multipleCorrect" : "singleCorrect", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider doing more typesafe parsing rather than checking string length (which isn't very resilient). for example, there could be an err in the spreadsheet
| row["Answer"].length > 1 ? "multipleCorrect" : "singleCorrect", | ||
| answers, | ||
| explanation: row["Reference"], | ||
| tags: row["tags"] ? row["tags"].split(",") : [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| tags: row["tags"] ? row["tags"].split(",") : [], | |
| tags: row["tags"] ? row["tags"].split(",").map(t => t.trim()) : [], |
again, a bit more resilient
mongodben
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple small things to make code a bit more resilient
Jira: https://jira.mongodb.org/browse/EAI-1257
Changes
Notes