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

[Question] Using var operator at nested level of array operators

Open alxpsr opened this issue 2 years ago • 2 comments

Suppose I have two arrays:

  • var arr1 = [ 52, 66, 88, 43, 98 ]
  • var arr2 = [ 41, 42, 43, 45, 46, 49, 52, 53, 79 ]

If some value from arr1 exists in arr2 i wanna return true

/** JS Implementation */
function check() {
    return arr1.some(item => {
        if (arr2.some(c => c == item)) {
            console.log(item)
            return true
        }

        return false
    })
}

I tried to do this with var operator and some but seems that scope of some has only local variables and doesn't have variables from closure. Is there a way to achieve it with default json-logic operators? (i mean without adding new operators via json-logic.add_operator())

Thanks in advance ^_^

alxpsr avatar Jul 29 '22 14:07 alxpsr

Hi @alxpsr, I actually have the same use case. Did you come up with a solution for this? Or did you end up implementing a custom operator?

Thanks.

jakemedal avatar Jan 30 '23 20:01 jakemedal

Hi @jakemedal , as far as i understood there is no standard operators for this. Out team implemented custom logic, but via C# on backend (since we use json-logic at frontend and backend)

alxpsr avatar Jan 31 '23 06:01 alxpsr