These 4 variables represent different players and their teams:
var player1 = {name:'ronaldo', team: 'europe/spain/realmadrid'}
var player2 = {name:'messi', team: 'europe/spain/barcelona'}
var player3 = {name:'gerald', team: 'europe/england/liverpool'}
var player4 = {name:'unknown english', team: 'europe/england'}
The goal is to create a JSON tree structure that organizes the information hierarchically based on region and team:
{
"text":"europe",
"leaf":false,
"children":[
{
"text":"spain",
"leaf":false,
"children":[
{
"text":"realmadrid",
"leaf":false,
"children":[
{
"text":"ronaldo",
"leaf":true
}
]
},
{
"text":"barcelona",
"leaf":false,
"children":[
{
"text":"messi",
"leaf":true
}
]
}
]
},
{
"text":"england",
"leaf":false,
"children":[
{
"text":"unknown english",
"leaf":true
},
{
"text":"liverpool",
"leaf":false,
"children":[
{
"text":"gerald",
"leaf":true
}
]
}
]
}
]
}