let data = [
{news: id1, users: [{user1}, {user2}, {user3}]},
{news: id2, users: [{user2}, {user4}, {user6}]},
{news: id3, users: [{user1}, {user2}, {user4}]}
]
So from the above data, I need to be able to group news items to form a template(let's consider a template consists strictly two news items). Then for every template, I need to match the corresponding user. Finally, when I'm done with creating all the templates I need to map remaining users to their respective news items.
I've added a sample output below
[id1,id2] : [user2]
[id2, id3] : [user2, user4]
[id3, id1] : [user1, user2]
[id2] : [user6]
[id1] : [user3]
How do I achieve this?
[id3] : []exist and have a value in your result example? Is it because it does not have a distinct value?