Creating a recursive loop using for each.

Options

Hi. I am working on a set of data that requires a loop to periodically update the variable being looped over and include the new items to be looped over. It is limited by a larger variable whose size will always be larger.

The structure of the larger variable is similar to the below where the smaller variable will be created.

[

[a,b,c],

[c,b,a],

[a,b],

[c,d],

[d,a],

[d,a],

[c,a]

]

The first thing I've set up is a loop that iterates over the larger variable.

Then I've set up a smaller loop on a smaller variable that checks the value on the larger one and if it is not contained in the smaller one, it adds the value to the smaller variable.

From testing I can tell the smaller variable is not being updated to be looped over on the inside.

Separately, I'm trying to understand break loop because it would make the stack run faster if it doesn't have to iterate over every item each time, but it seems to break the outer loop as well. Can break loop only break an inner loop and not an outer loop?

Best Answer

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Is the objective to just pull [a,b,c,d] from the original data structure?

  • enyarick
    enyarick Member
    Options

    Hi @Ray Deck

    The objective is to return the array below that has only unique elements. A counter will show how many times each element shows up.

    [

    [a,b,c],

    [a,b],

    [c,d],

    [d,a],

    [c,a]

    ]

  • enyarick
    enyarick Member
    Options

    This is amazing @Ray Deck!

    I got it to work pretty quickly but have agonized over why it works so well and tried to do a few variations. Need to chew on this some more.

    Hadn't come across the "has" filter at all so that's an awesome reveal.

    Objects & keys also trying to wrap my head around.

    Thanks loads for your excellent video.