feat: question analysis in view

This commit is contained in:
IlyaDoronin 2023-12-05 10:34:41 +03:00
parent 64601e74de
commit 8e6852f38c

@ -37,13 +37,16 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => {
const followNextStep = () => { const followNextStep = () => {
if (answers.length) { if (answers.length) {
const answer = answers.find(
({ questionId }) => questionId === question.content.id
);
let readyBeNextQuestion = ""; let readyBeNextQuestion = "";
question.content.rule.main.forEach(({ next, rules }) => { question.content.rule.main.forEach(({ next, rules }) => {
let longerArray = Math.max( let longerArray = Math.max(
rules[0].answers.length, rules[0].answers.length,
[answers.at(-1)?.answer].length [answer?.answer].length
); );
for ( for (
@ -51,13 +54,12 @@ export const Footer = ({ setCurrentQuestion, question }: FooterProps) => {
i < longerArray; i < longerArray;
i++ // Цикл по всем эле­мен­там бОльшего массива i++ // Цикл по всем эле­мен­там бОльшего массива
) { ) {
if (rules[0].answers[i] === answers.at(-1)?.answer) { if (rules[0].answers[i] === answer?.answer) {
readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны readyBeNextQuestion = next; // Ес­ли хоть один эле­мент от­ли­ча­ет­ся, мас­си­вы не рав­ны
} }
} }
}); });
if (readyBeNextQuestion) { if (readyBeNextQuestion) {
const nextQuestion = getQuestionByContentId(readyBeNextQuestion); const nextQuestion = getQuestionByContentId(readyBeNextQuestion);
if (nextQuestion) { if (nextQuestion) {