I'm facing a situation like this:
const idMappings = {
// id: parentId
"2": "1",
"3": "1"
}
const inputData = [
{
id: "1",
data: [1],
},
{
id: "2",
data: [2]
},
{
id: "3",
data: [3]
},
{
id: "4",
data: [4]
}
]
const expectedOutput = [
{
id: "1",
data: [1,2,3]
},
{
id: "4",
data: [4]
}
]
Using the 'idMappings' array, I aim to create a configuration that will determine which object in the 'inputData' array should have merged data (objects without an id-parentId pair defined should remain unchanged). The code above serves as a better demonstration of what I'm trying to achieve. I've attempted some mappings but haven't achieved desirable results. Is there a more efficient way to define the 'idMappings' array to simplify this scenario? Any suggestions would be greatly appreciated.