Using the Unique filter on an array of arrays.
Hi.
I'm looking through data that needs me to go through an array that looks like the below
[[a,b,c],[c,b,a],[a,b],[c,d],[d,a],[d,a],[c,a]]
and from this data lift unique groupings and count them so that we have
[a,b,c] = 2
[d,a] = 2
[a,b] = 1
[c,a] = 1
[c,d] = 1
I've used the unique filter on the main array hoping to get the unique combinations then count them afterwards, but I keep getting hit with an unknow error exception.
Is there something I'm doing that's wrong?
Thanks!
Answers
-
Hello @enyarick,
Regarding the error you are facing, it is possible that your main array does not have the correct format.
To construct such an array on Xano you can you use thepush
filter on an array, like this:Then using the
unique
filter like this:And the
uniqueArrays
result will be as such:While this implementation doesn't directly returns what you need, it should allow you to resolve the error you mentioned.
If you need any assistance regarding the further implementation, let me know! -
Thanks for this @BUYNOCODEAPPS!.
Challenge is here we have a repeated array at position 0 and 1. It's just the arrangement which is different.
What I'm looking for is to have unique items only returned. Sorting the smaller arrays would definitely help. Let me try and see if that helps.
The next stage will be to count how many times each unique array appears so if I can get part 1, then part 2 should be doable. -
I'm testing using a for each loop where the array is iterated through and each sub-array is sorted and compared to a sorted array that exists. This also doesn't seem to work.
-
Hello again @enyarick,
In a pretty high level design, this is what I would probably do:The
newArray
should then be filtered for unique entries. -
Thanks for this @Lefteris - Buynocodeapps!
Unfortunately, this append filter doesn't seem to work inside a for each loop.
[
[a,b,c],
[d,a],
[a,b],
[c,a],
[c,d]
]
The array looks like this and I'm iterating through an array with the intent each time to add an element to the array e.g. adding [c,b,a] to the end of this array so that it now looks like this
[
[a,b,c],
[d,a],
[a,b],
[c,a],
[c,d],
[c,b,a]
]
I'm able to do this from outside a for each loop using both add to end/beginning of array as well as append.
But from inside the for each loop I'm getting nothing being added.
Still experimenting.
Thanks!
-
Thanks for this @Lefteris - Buynocodeapps!
Unfortunately, append doesn't seem to work.
[
[a,b,c],
[d,a],
[a,b],
[c,a],
[c,d],
]
I trying to use a for each loop to find an element from an array like the one above and compare it to the rest. If it exists, skip. If it doesn't add it to the unique array. I'm able to match the elements, but can't seem to add a new element to the "arrayofarrays" either using a push, or using an append.
I've tried to update variable where I'm appending the new array. I've also tried adding to end/beginning of array.
So if I want to add [c,b,a] to the above the result should be
[
[a,b,c],
[d,a],
[a,b],
[c,a],
[c,d],
[c,b,a]
]
Any ideas?
-
Hi again @enyarick,
Are you sure it doesn't work?
The append should look something like this:Maybe you can add a screenshot of the debugger, so I can understand better what issue are you facing.
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