CacheControl / CacheControl/json-rules-engine

Question: Comparing Distinct Arrays of Objects

Open
#258 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.1k
Forks
507
PR merge metrics
No merged PRs in 30d

Description

Hello,

I am trying to compare an array of objects to check for a specific set of objects to be present in any of them, but not across all of them, specifically lets take this rule:
```
const arrayRule = {
conditions: {
any: [
{
all: [
{
fact: 'data',
path: '$.[*].equalityTest',
operator: 'equal',
value: 50,
},
{
fact: 'data',
path: '$.[*].anotherTest',
operator: 'equal',
value: 50,
},
],
},
],
},
event: {
type: 'arrayRule',
},
};
```

This is the first iteration of the rule I came up with, it is incorrect, but I wanted to give an idea of what I am aiming for.

Specifically here, we have a rule where I want `equalityTest` to equal `50` and `anotherTest` to also equal `50`. But I want them to equal those values in the same object, such that:
*THIS SHOULD RETURN FALSE*
```
const facts = {
data: [
{
anotherIntegerFact: 1,
equalityTest: 50,
},
{
anotherIntegerFact: 50,
equalityTest: 40,
},
],
};
```

*THIS SHOULD RETURN TRUE*
```
const facts = {
data: [
{
anotherIntegerFact: 50,
equalityTest: 50,
},
{
anotherIntegerFact: 40,
equalityTest: 40,
},
],
};
```

Would love any suggestions or ideas on a way to tackle this. One thought was I could write my own `operator` and add it to the registry of operators on our end, but before I did so, I wanted to validate that is needed.

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.