Creating a recursive loop using for each.
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
-
Got it. I made a small video illustrating how to work this - maybe it helps your situation?
Answers
-
Is the objective to just pull [a,b,c,d] from the original data structure?
-
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]
]
-
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.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback