How do i recreate this code in xano ?

Options

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

Answers

  • liam
    liam Member
    edited September 2023
    Options

    @arturosanz i've tried those combinations, but still not working. been trying for hours.

    do you mind sharing the solution with function stack ?

  • arturosanz
    arturosanz Member ✭✭
    edited September 2023
    Options

    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:

    1. Xano doesn't have any array function to edit or remove an element by its index. 😥
    2. Xano doesn't allow to include the index variable into a subpath expression. 😥
    3. 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.

  • liam
    liam Member
    Options

    @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.