Trying to restructure my map in order to see it as a Tree.
data :
{
"FacebookAPI": [
"TwitterAPI",
"TiktokAPI",
"TeslaAPI"
],
"TeslaAPI": ["TwitterAPI"],
"TiktokAPI": ["WhatsAppAPI"],
"BitcoinAPI": [],
"WhatsAppAPI": [],
"GoogleAPI": [
"FacebookAPI",
"TeslaAPI",
"TwitterAPI",
"TiktokAPI"
]
}
expected output
{
"GoogleAPI": [
{
"FacebookAPI": [
{ "TeslaAPI": { "TwitterAPI": [] } },
"TwitterAPI",
{ "TiktokAPI": { "WhatsAppAPI": [] } },
]
}
]
}
my goal is to calculate the depth of each parent item :
Example :
Google calls : Facebook + Tesla + Twitter + Tiktok + WhatsAppAPI => depth should be 5
Whatsapp calls : CryptoEndToEnd => depth should be 1
can anyone help me out.