json-logic icon indicating copy to clipboard operation
json-logic copied to clipboard

Add array "intersection" operator

Open laszlo-hermann-trimble opened this issue 1 year ago • 0 comments

Currently there is no way to find out if there are any common elements in two arrays in the data object. This could be achieved by adding a globally available intersection function which returns the common elements in two arrays:

  {"intersection": [{"var": "list1"}, {"var": "list2"]}]

Deciding if there are any elements common to both arrays:

  {
    "some": [{"intersection": [{"var": "list1"}, {"var": "list2"]}], "true"]
  }

Currently this cannot be achieved with the current set of operators since var operations are relative to the array element being tested.

I am aware that a custom operator would solve this problem but instead of writing it privately, I'd prefer contributing so that others could take it into use as well.

What is the recommended way to contribute? Raise a PR into this repo and the JS implementation?

laszlo-hermann-trimble avatar Jan 12 '24 14:01 laszlo-hermann-trimble