Reputation: 79
Let's say that request.resource.data[field]
is a list. I am trying to check if any of the items in the list is a duplicate of the other items. In other words, I am checking if any of the items are repeated more than once inside the list. I read the documentation and reference related to list, and did not find a way to implement this. Is this possible to do?
Upvotes: 0
Views: 102
Reputation: 317402
You can check to see if there are any duplicates in a List type field by:
If the size of the set is less then the size of the list, then you know that there was at least one duplicate that got removed. So, something like this will return true if there was a duplicate in the list:
listField.toSet().size() < listField.size()
Upvotes: 2