Consider the following two javascript objects:
Object A:
{
specialPropertyA: string,
partTime: boolean,
role: { key: string, label: string }
}
Object B:
{
specialPropertyB: string,
partTime: boolean,
role: { key: number, label: string }
}
Now, consider an arrayA: ObjectA[]
and an arrayB: ObjectB[]
.
I am looking for a concise way to determine:
If any of the ObjectA's have partTime === true
AND role.key === 1
, are there any ObjectBs, which fulfill the same requirements? I want to check the same for role.key === 2
.
I know I could do sth like:
if(
arrayA.filter(objectA => objectA.partTime === true && objectA.role.key === 1)
&& arrayB.filter(objectB => objectB.partTime === true && objectB.role.key === 1)
|| arrayA.filter(objectA => objectA.partTime === true && objectA.role.key === 2)
&& arrayB.filter(objectB => objectB.partTime === true && objectB.role.key === 2)
)
But I don't like this solution at all, especially since I am repeating the same code for key 2. Any suggestions as on how to make this more concise?