I have such a case:
const ids = {
// id: parentId
"2": "1",
"3": "1"
}
const input = [
{
id: "1",
data: [1],
},
{
id: "2",
data: [2]
},
{
id: "3",
data: [3]
},
{
id: "4",
data: [4]
}
]
const output = [
{
id: "1",
data: [1,2,3]
},
{
id: "4",
data: [4]
}
]
With this ids I wanted to create some kind of config, which will determine which object in input array should have merged data (if there is no id-parentId pair defined, it should stay as it is). I belive code above is better explanation than this story. I tried with some mappings but without any nice result. This 'ids' array is an example, maybe there is a better way to define it so it will simplify the case? What do you think? I will be grateful for any hint
map()if the output is a different size from the input.