I'm trying to find the intersection set within an array only containing type 1 and 2. Can you help me with that?
var arr = [
{
id: 1, auths: [
{ authId: 1, type: 1, value: 'Test1' },
{ authId: 2, type: 1, value: 'Test2' },
{ authId: 3, type: 2, value: 'Test3' },
{ authId: 4, type: 2, value: 'Test4' },
{ authId: 99, type: 3, value: 'Test' }
]
},
{
id: 2, auths: [
{ authId: 1, type: 1, value: 'Test1' },
{ authId: 2, type: 1, value: 'Test2' },
{ authId: 4, type: 2, value: 'Test4' },
{ authId: 99, type: 3, value: 'Test' }
]
},
{
id: 3, auths: [
{ authId: 1, type: 1, value: 'Test1' },
{ authId: 4, type: 2, value: 'Test4' },
{ authId: 5, type: 1, value: 'Test5' },
{ authId: 99, type: 3, value: 'Test' }
]
},
{
id: 4, auths: [
{ authId: 1, type: 1, value: 'Test1' },
{ authId: 3, type: 2, value: 'Test3' },
{ authId: 4, type: 2, value: 'Test4' },
{ authId: 99, type: 3, value: 'Test' }
]
}
]
This is the desired output:
var outArr = [
{ authId: 1, type: 1, value: 'Test1' },
{ authId: 4, type: 2, value: 'Test4' }
]
I have attempted the following;
arr.map(p=>p.auths).filter(x=> arr.map(p=>p.auths).includes(x))
and also this;
var _map=arr.map(p=>p.auths);
_map.filter(({authId:id1})=> _map.some(({authId:id2})=> id2!==id1))
I tried a few more things but none of them worked. Is there a way to achieve this without using a loop?