How do i recreate this code in xano ?
![liam](https://us.v-cdn.net/6037124/uploads/userpics/3H7104LQR226/nMYKMXK20IPV2.png)
Hi im trying to recreate this function on xano but im lost,
this is the code
this is the result i'm expecting
[
{ date: "01-01-2021, name: { "liam", "liam1" } },
{ date: "01-02-2021, name: { "max", "maxwell" } },
]
How do i recreate this with function stack ?
Best Answer
-
Cool Problem! I took a run at solving it to share the concepts in it:
Answers
-
You have the solution in these two pages:
-
@arturosanz i've tried those combinations, but still not working. been trying for hours.
do you mind sharing the solution with function stack ? -
The solution without lambda functions is a bit complicated. You will have to use loops and conditionals to iterate the objects and arrays. I'll give you a few hints.
The result you should expect is this:
[
{ date: "01-01-2021, name: [ "liam", "liam1" ] },
{ date: "01-02-2021, name: [ "max", "maxwell" ] },
]
not this:
[
{ date: "01-01-2021, name: { "liam", "liam1" } },
{ date: "01-02-2021, name: { "max", "maxwell" } },
]
because objects must have key value pairs, but arrays are a list of values.
Some uncomfortable limitations are:
- Xano doesn't have any array function to edit or remove an element by its index. 😥
- Xano doesn't allow to include the index variable into a subpath expression. 😥
- Xano doesn't have any sort array function. 😥
However, you can still achieve what you want if you are able to provide the original ungrouped array sorted by date. If we didn't have at least one of those limitations, we could have made the function to work well with unsorted elements in the original array.
If you can assure the original array is sorted, then here is the function. Just keep in mind that the result array will be sorted backwards, because we can only easily manipulate the index 0 hardcoded.
-
@Ray Deck @arturosanz thank you for the detail answer ! both of the solution above worked and we are going to go with ray deck's solution because it has shorter function stack.
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