I am grappling with a complex nested multidimensional array that resembles the following structure in JSON format:
[
{
"Object": "Car",
"Child": [
{
"Object": "Toyota",
"Child": [
{
"Object": "Prius"
},
{
"Object": "Yaris"
}
]
},
{
"Object": "Honda",
"Child": [
{
"Object": "Accord"
},
{
"Object": "Civic",
"Child": [
{
"Object": "Sedan"
},
{
"Object": "Coupe"
}
]
}
]
}
]
}
]
I'm seeking a way to determine if one object is a direct descendant of another within this hierarchy.
For instance, "Sedan" is a direct descendant of "Civic", "Honda", and "Car"; however, it is not a direct descendant of "Coupe", "Accord", "Toyota", "Prius", or "Yaris".
The goal is to develop a function similar to the following:
function Lineal_Descendant(A,B){
/*perform logic here*/
}
Lineal_Descendant("Sedan","Civic") /*should return true*/
Lineal_Descendant("Sedan","Toyota") /*should return false*/
Lineal_Descendant("Prius","Honda") /*should return false*/
Lineal_Descendant("Yaris","Car") /*should return true*/