I need to group together all the pId together which has same cId entries. I have the following data -
const data = [{pId:"a", cId: [1,2]}, {pId:"b", cId: [1,2]}, {pId:"c", cId: [3]}];
const data1 = [{pId:"a", cId: [1,2,3]}, {pId:"b", cId: [1,2]}, {pId:"c", cId: [3]}];
const data2 = [{pId:"a", cId: [1,2,3]}, {pId:"b", cId: [1,2,3]}, {pId:"c", cId: [3]}];
Expected output -
data = [{pId:["a","b"], cId: [1,2]}, {pId:["c"],cId: [3]}]
data1 = [{pId:["a","b"], cId: [1,2]}, {pId:["a","c"],cId: [3]}]
data2 = [{pId:["a","b"], cId: [1,2,3]},{pId:["a","b","c"],cId: [3]}]
Please help, in the approach. Kindoff stuck, not able to think which qualifies all the cases