Answer the question
In order to leave comments, you need to log in
How to find the longest branch in a tree?
JavaScript.
There is a step by step form. You need to show how much is left to answer, depending on the answers.
Sample data. Nesting can be any.
const quest = [
{
title: 'q1',
answers: [
{ title: 'a1-1' },
{
title: 'a1-2',
next: [
{
title: 'q1-2-1',
answers: [
{ title: 'a1-2-1-1' },
{ title: 'a1-2-1-2' }
]
}
]
},
{
title: 'a1-3',
next: [
{
title: 'q1-3-1',
answers: [
{ title: 'a1-3-1-1' },
{ title: 'a1-3-1-2' },
{
title: 'a1-3-1-3',
next: [
{
title: 'q1-3-1-3-1',
answers: [
{ title: 'a1-3-1-3-1-1' },
{ title: 'a1-3-1-3-1-2' },
{ title: 'a1-3-1-3-1-3' }
]
}
]
}
]
}
]
}
]
},
{
title: 'q2',
answers: [
{ title: 'a2-1' },
{ title: 'a2-2' },
]
},
{
title: 'q3',
answers: [
{ title: 'a2-1' },
{
title: 'a2-2',
next: [
{
title: 'q2-2-1',
answers: [
{ title: 'a2-2-1-1' },
{ title: 'a2-2-1-2' }
]
}
]
},
{
title: 'a2-3',
next: [
{
title: 'q2-3-1',
answers: [
{ title: 'a2-3-1-1' },
{ title: 'a2-3-1-2' }
]
}
]
}
]
},
]
Answer the question
In order to leave comments, you need to log in
No, if there is a branch at the current step with a different number of questions.
You can only show the percentage of the maximum possible number of answers in this thread:
[progress, in %] = 100*([passed number of questions in the current thread] / [maximum number of questions in the current thread])
To find the number of passed / remaining steps on a particular question ("node"), you need to follow from each "node" of the "tree" to the "root" of the "tree" (to the beginning of the test / survey) and count the number of connections and immediately mark the "edges" as much as possible -possible value of the "depth" of the given "branch" from the current "node".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question