I am new to working with JavaScript, coming from the Python world. I need some assistance.
Currently, I am retrieving data from the back end that has the following structure:
{
"Airports": {
"BCN": {
"Arrivals": [{ "flight": "BIO", "time": "1:00" , "passengers": 10}, { "flight": "VGU", "time" : "2.00","passengers": 20 }, {"flight": "MEX", "time": "3.00", "passengers": 30 } ],
"Departures": [{ "flight": "BIO", "time": "1:00" }, { "flight": "VGU", "time" : "2.00" }, {"flight": "MEX", "time": "3.00" }]
},
}
}
My goal is to extract Arrival/Departure data for each airport and transform it into a list of dictionaries containing key-value pairs as shown below:
FlightData.Airports.BCN.Arrivals
[
{"0:00":[]},
{"1:00":["flight": BIO, "passengers": 10]},
{"2:00":["flight": VGU, "passengers": 20]},
{"3:00":["flight": MEX, "passengers": 30]},
]
I have tried the following approach so far:
let arrivalDict = Object.keys(arrivals).reduce(
(acc: any, k: any) => (
(acc[arrivals[k]] = [...(acc[arrivals[k]] || []), k]), acc
),
{}
);
Should I consider using Lodash for this task?