How to make combinations in expression.

I'm sure this has to be a relatively simple problem, but I can't seem to figure out the answer. I want all the combinations you can have selecting 2 items from the same array, repeats allowed.

Say my array is {1,2,3,4,5}

I want to output {11, 12, 13, 14, 15, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35, 41, 42, 43, 44, 45, 51, 52, 53, 54, 55}

And if possible, I want to expand this to have a means of creating 3 and 4 and 5 digit combinations.

OriginalPostID-273492

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    I've come up with the following pair of rules which seems to do what you want. See code below and screenshot attached. Note that I didn't include a lot of error checking or null handling, which you would want to do if you implement this for real use.

    Parent Rule (named i.e. TEST_textCombinations_parentRule):
    with(
    local!array: {
    "1", "2", "3", "4", "5" /* for example */
    },

    apply(
    rule!TEST_textCombinations_subRule(
    array: local!array,
    index: _
    ),
    enumerate(length(local!array))+1
    )
    )

    Child Rule (TEST_textCombinations_subRule):
    apply(
    fn!concat,
    merge(
    repeat(
    length(ri!array),
    index(ri!array, ri!index)
    ),
    ri!array
    )
    )

Reply
  • 0
    Certified Lead Developer
    I've come up with the following pair of rules which seems to do what you want. See code below and screenshot attached. Note that I didn't include a lot of error checking or null handling, which you would want to do if you implement this for real use.

    Parent Rule (named i.e. TEST_textCombinations_parentRule):
    with(
    local!array: {
    "1", "2", "3", "4", "5" /* for example */
    },

    apply(
    rule!TEST_textCombinations_subRule(
    array: local!array,
    index: _
    ),
    enumerate(length(local!array))+1
    )
    )

    Child Rule (TEST_textCombinations_subRule):
    apply(
    fn!concat,
    merge(
    repeat(
    length(ri!array),
    index(ri!array, ri!index)
    ),
    ri!array
    )
    )

Children
No Data