I'm dealing with a pretty complex workflow that I want to represent as a JavaScript data structure. The flow is essentially a set of questions and answers where the answer to one question affects which question is asked next. The following is a basic example of what the flow might look like:
I'm not sure how to convert this flow into a JavaScript object that's easy to work with. I would ideally like to have a structure that's easy to loop/recurse through and that is easily modifiable, so that if someone wanted to change the flow at a later point, they could do so without having to make too many changes.
I feel like this is some sort of weird tree structure where nodes can have more than one parent. (I'm not sure what data structures like this are called.)
Anyway, the only idea I've had is to assign an ID to each node, and then create an array of node objects like the following:
{
id: 5,
parents: [2, 3],
children: [6, 7, 8]
}
However, that seems really inflexible when it comes to looping through the node objects (I could be wrong though).
If anyone could please offer some instruction/guidance on what kind of data structure(s) I should look into and possibly how to implement them in JavaScript, I would be greatly appreciative.
Thank you very much in advance.