Hey all, I'm interested in writing a simple expression rule which will

Certified Lead Developer
Hey all,
I'm interested in writing a simple expression rule which will take two arrays (let's say integers, for now), ri!bigArray and ri!smallArray -- and the return will be the indices (if any) of where any members of 'small' are in 'big'. Sort of like a "where" function which can accept multiple targets. I've tried various looping, array, and set functions, and can't quite come up with something which actually works. If anyone has any ideas I'd really appreciate it....

OriginalPostID-69864

OriginalPostID-69864

  Discussion posts and replies are publicly visible

Parents
  • I would discourage the use of undocumented functions.

    Instead, you could use reduce() and 2 expression rules to achieve the desired result:

    Rule 1
    --------
    Name: appendIndexIfContains
    Inputs: indices (Integer, Multiple), bigArrayValue (Integer), bigArrayIndex (Integer), smallArray (Integer, Multiple)
    Expression: =if(contains(ri!smallArray,bigArrayValue),append(ri!indices,ri!bigArrayIndex),ri!indices)

    Rule 2
    --------
    Name: getIndicesWhereBigContainsSmall
    Inputs: bigArray (Integer, Multiple), smallArray (Integer, Multiple)
    Expression: =reduce(rule!appendIndexIfContains, {},merge(ri!bigArray,enumerate(length(ri!bigArray))+1),ri!smallArray)
Reply
  • I would discourage the use of undocumented functions.

    Instead, you could use reduce() and 2 expression rules to achieve the desired result:

    Rule 1
    --------
    Name: appendIndexIfContains
    Inputs: indices (Integer, Multiple), bigArrayValue (Integer), bigArrayIndex (Integer), smallArray (Integer, Multiple)
    Expression: =if(contains(ri!smallArray,bigArrayValue),append(ri!indices,ri!bigArrayIndex),ri!indices)

    Rule 2
    --------
    Name: getIndicesWhereBigContainsSmall
    Inputs: bigArray (Integer, Multiple), smallArray (Integer, Multiple)
    Expression: =reduce(rule!appendIndexIfContains, {},merge(ri!bigArray,enumerate(length(ri!bigArray))+1),ri!smallArray)
Children
No Data