I’m looking for a better way to implement a decision tree in javascript. Being very new to programming I have a very limited number of tools in my toolbox. The only ways I know to do this are:
.with a huge ugly hard to maintain and follow if else if statement
.I could use a switch/case statement and do a state machine type thing.
Suggestions and theories are appreciated. Also, small code examples would be very helpful. Thanks for taking a look.
Dale
If it is a really big tree, and especially if it is generated from data, you could treat the decision functions like data, using a functional approach. For example:
Using this implementation, you can arbitrarily nest your tree: