Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logic jump for other option #1922

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/surveys/src/components/general/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ export function Survey({
if (currQues?.logic && currQues?.logic.length > 0) {
for (let logic of currQues.logic) {
if (!logic.destination) continue;

if (
currentQuestion.type === "multipleChoiceSingle" ||
currentQuestion.type === "multipleChoiceMulti"
) {
const choice = currentQuestion.choices.find((choice) => choice.label === responseValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace the find method with a Map for constant time lookups, improving performance especially for larger arrays.

Suggested change
const choice = currentQuestion.choices.find((choice) => choice.label === responseValue);
const choicesMap = new Map(currentQuestion.choices.map(choice => [choice.label, choice]));
const choice = choicesMap.get(responseValue);

// if choice is undefined we can determine that, "other" option is selected
if (!choice) {
if (evaluateCondition(logic, "Other")) {
return logic.destination;
}
}
}
if (evaluateCondition(logic, responseValue)) {
return logic.destination;
}
Expand Down
Loading