I won't write the code for you, but basically, it's the same with any other language.
You traverse through every right child until you know that it's the end node.
How to use JavaScript to access JSON?
var tree =
{
parent : [
{
//child1 details
},
{
//child2 details
},
]
}
For JSON key access, use tree.<key> (dot)
or tree['key']
. In this case, tree.parent
or tree["parent"]
.
For Array access, use indices. Since parent
is an array, you can access the children by tree.parent[0]
or tree['parent'][0]
.
I prefer the dot method though, to distinguish visually JSONs and arrays.
Also, you need something to distinguish a right child and a left child. You can either make it a convention to make the right child as the [0]
index in the array, or you can add another value per node that says that its right or left.