I have been struggling with a problem that I am trying to solve in a performant and better way. Basically I have a Collection, or in simpler terms an array of objects. I'll paste the collection down:
[
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "mac",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "linux",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "mac",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "linux",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
{
"pluginId": "fy9h-dKw2",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
]
Now the reason that I want to change it a specific format is that I could use it with a UI library that dictates it to be in a specific format. I'll paste the end result down:
[
{
"name": "fy9h-dKw", "children": [
{
"name": "4.26", "children": [
{
"name": "1", "children": [
{
"name": "mac", "children": [
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "mac",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
"name": "windows", "children": [
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
"name": "linux", "children": [
{
"pluginId": "fy9h-dKw",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "linux",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
}
]
}
]
}
]
},
{
"name": "fy9h-dKw1", "children": [
{
"name": "4.26", "children": [
{
"name": "1", "children": [
{
"name": "mac", "children": [
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "mac",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
"name": "windows", "children": [
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
},
],
"name": "linux", "children": [
{
"pluginId": "fy9h-dKw1",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "linux",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
}
]
}
]
}
]
},
{
"name": "fy9h-dKw2", "children": [
{
"name": "4.26", "children": [
{
"name": "1", "children": [
{
"name": "mac", "children": [
{
}
],
"name": "windows", "children": [
{
"pluginId": "fy9h-dKw2",
"pluginVersion": 1,
"pcVersion": "4.26",
"platform": "win",
"previews": [
{
"uri": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.jpg"
}
],
"pluginUrl": "/e2d4-dKv/4.26/1/7f4bc5e9-3721-4f83-abd4-75792ae75e3d.zip"
}
],
"name": "linux", "children": [
{
}
],
}
]
}
]
}
]
}
]
To clear out the confusion with the mess of this end result, all I want is to group them by their pluginId, then by their pcVersion, then by their pluginVersion, and in end by their platform. I'll just paste the format of end result:
[
{
"name": "pluginId", "children": [
{
"name": "pcVersion", "children": [
{
"name": "pluginVersion", "children": [
{
"name": "mac", "children": [
{
}
],
"name": "windows", "children": [
{
}
],
"name": "linux", "children": [
{
}
],
}
]
}
]
}
]
}
]
I found out about the Lodash Library groupBy method that is excellent. But I have to write a lot of bad loops for it and its too complicated.
I would really appreciate any hints or leads to solve it as I have been stuck on it for a lo\t of hours now and getting extremely frustrated. Thanks in advance.