Check if two lists are equal

Is there a way to compare two lists of things and see if they contain the same elements (same unique ids)?

Hi @furnys :slight_smile: Yes this is possible using the intersects with operator. Here is an example:

Preview:

Editor:

In this example, there is a “Conversation” data type which stores two lists: a list of Messages, and a list of Users (“Participating Users”):

In the app data tab, there are two Conversation entries, each with the same list of Users in the “Participating Users” field:

Back on the page, each Conversation is displayed in a group, and each Conversation’s “Participating Users” are displayed in repeating groups, within the outer Conversation groups:

Conversation 1:


Conversation 2:


To check if the two Conversations have the same Participating Users and the same number of Participating Users, we can use this expression (in the text’s conditional):

"When Group Conversation 1's Conversation's _Participating Users_ **intersect with** Group Conversation 2's Conversation's _Participating Users_:count
(This part of the expression is comparing the Conversations’ Participating Users lists, and returning the entries that are the same in each list)

**is equal to** Group Conversation 1's Conversation's Participating Users:count
(This checks to see if the number of Users that were found to be the same in each list, is equal to the total number of Conversation 1’s Participating Users list)

and Group Conversation 1's Conversation's Participating Users:count **is equal to**
Group Conversation 2's Conversation's Participating Users:count"

(This makes sure that the total number of Participating Users in Conversation 1, and the total number of Participating Users in Conversation 2, are equal to each other).

In preview mode, we can see that this works when the lists have the same five Users:

But if we remove two Users (for example) from one of the Conversation’s List of Participating Users, the conditional is no longer true since the lists are not the same size, and the “Lists are not equal to each other” default text will display:

That should work! But feel free to let me know if you have any questions! :slight_smile:

10 Likes

Sorry for the delayed response @fayewatson and thanks for your wonderfully detailed answer!
I’ve been involved in other things in the last few weeks that led me astray from Bubble.
I’m trying it asap!

2 Likes

Awesome! No problem at all! Let me know if you have any questions when setting it up! :slight_smile:

This topic was automatically closed after 70 days. New replies are no longer allowed.