Effective Methods for Comparing Array Lengths on Make.com
Problem: Comparing Array Lengths
Imagine this scenario: A customer purchases an expansion pack from our website and an API updates the expansion code. You're tasked with comparing the Users Expansions on the API with the Expansions purchased to ensure everything is updated. You create two arrays to compare and use the Array operators: Array length equal to. However, the Arrays are not equal to each other, yet the filter passed it. So, what is a better Filter to use in order to compare two arrays to make sure they both have the exact same values?
Solution: Sorting and Encoding
Here's a step-by-step solution:
- Create more Variables and call them Array1 and Array2.
- Sort the Arrays by asc so that all of the values in the array are ascending.
- Convert the Arrays into a Base64 encode.
- Compare to make sure the values are equal.
This solution works because the Base64 can exactly encode and decode any amount of text, even arrays. It's a neat trick that might not immediately come to mind, but it's effective.
Troubleshooting Tips
If you're still having trouble, you could also try converting the arrays into a string. Here's how:
- Sort the arrays in the same way (asc).
- Join() each array with some delimiter, for example a comma or hashtag etc.
- Now that the arrays are a string, you can compare them with the "equals" comparison.
Summary
Comparing arrays can be tricky, but with the right approach, it's definitely doable. Whether you choose to use Base64 encoding or convert the arrays into a string, the key is to ensure that the arrays are sorted in the same way and that you're comparing the right values. Happy automating!
You do have further questions?
Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.