How can I do recursion?
![pete letkeman](https://us.v-cdn.net/6037124/user_avatars/5524134.jpg)
I have the following table setup
I want to be able to enter a value of 7 and I want to get an array like [7,5,3,2,1].
Or if I enter a value of 3 I want to get an array like [3,2,1].
Generally speaking, when you do recursion you pass the function as a parameter to itself e.g.
int fib(int n) {
if (n <= 1) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
This is what I currently have
https://www.loom.com/share/7fd496610665440f9354fad604a008d1
How can I pass a function to itself in Xano and/or what exactly am I don't incorrectly?
Best Answers
-
-
Yeah, technically, this is not recursion.
In general, Doing recursion in no-code tools is always tricky.
You can use "lambda" and write the javascript code to write the recursion function.
Answers
-
Instead of recursion-
Step 1- Query all the record with custom query where id<="value" and sort by "id" - descending.
And return the "table.id" as the json array.
-
Okay, let's try a different example or two
Input 9, output [3,2,1]
Input 8, output [5,3,2,1]
There is no guarantee that the child's values will be less than the parent's values or that there will be an easy-to-guess sequence for the child's values as the system is used.
The only guarantee is that at some point in time there will not be any records found for the given parent id.
-
@pete letkeman How are you getting [3,2,1] or [5,3,2,1]?
-
Opps, I did that wrong.
It should be the following:
Input 8, would return [3,2,1]
Id = 8, parentId = 3 (root)
Id = 3, parentId = 2 (super admin)
id = 2, parentId = 1 (everyone)
id = 1, parentId = null
--------------------------
Input = 9, would return [2,1]
Id = 9, parentId = 2 (super admin)
id = 2, parentId = 1 (everyone)
id = 1, parentId = null
-
That looks like it would work.
I'm not too sure that I'd call that recursion as the function/method is not calling itself, which is fine as not everything needs recursion.
That said, can you do recursion programming with Xano?
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