-
Notifications
You must be signed in to change notification settings - Fork 75
(EAI-1257) handle multiple correct and more answer options #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
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
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