Skip to content

Conversation

yakubova92
Copy link
Collaborator

Jira: https://jira.mongodb.org/browse/EAI-1257

Changes

  • script is able to process answer options A-F (previously, A-D)
  • script can handle questions that have multiple correct answers

Notes

@yakubova92 yakubova92 changed the title process answer options through F, handle multiple correct (EAI-1257) handle multiple correct and more answer options Aug 20, 2025
Comment on lines +12 to +21
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
Copy link
Collaborator

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?

Comment on lines +10 to +11
const handleAnswers = (row: any) => {
const correctAnswers = row.Answer.trim()?.split("") || [];
Copy link
Collaborator

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.

Comment on lines +37 to +38
questionType:
row["Answer"].length > 1 ? "multipleCorrect" : "singleCorrect",
Copy link
Collaborator

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(",") : [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags: row["tags"] ? row["tags"].split(",") : [],
tags: row["tags"] ? row["tags"].split(",").map(t => t.trim()) : [],

again, a bit more resilient

Copy link
Collaborator

@mongodben mongodben left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants