Embarking on a new project, I find myself in unfamiliar territory. The data at hand is structured as follows:
{
domain1.com: [
{ city: "New-York" },
{ city: "Denver" },
{ city: "Las-Vegas" },
{ city: "Boston" },
]
},
{
domain2.com: [
{ city: "Miami" },
{ city: "Las-Vegas" },
{ city: "Boston" },
]
},
{
domain3.com: [
{ city: "New-York" },
{ city: "Miami" },
{ city: "Las-Vegas" },
{ city: "Chicago" },
]
}
The challenge now presents itself - can we restructure this data to form a list where each city is paired with its associated domain names? Consider the desired output below:
{
New-York: [
{ domain: "domain1.com" },
{ domain: "domain3.com" },
]
},
{
Denver: [
{ domain: "domain1.com" },
]
},
{
Las-Vegas: [
{ domain: "domain1.com" },
{ domain: "domain2.com" },
{ domain: "domain3.com" },
]
},
{
Boston: [
{ domain: "domain1.com" },
{ domain: "domain2.com" },
]
},
{
Miami: [
{ domain: "domain2.com" },
{ domain: "domain3.com" },
]
},
{
Chicago: [
{ domain: "domain3.com" },
]
},