How to Create Unique Combinations with Cartesian Product
The Cartesian Product is the set of unique combinations derived from a pair of sets. More on Wikipedia.
This code works by comparing pairs from an array of sets using the reduce and map functions, producing unique combinations.
If you are interested to understand the cartesian product more deeply, watch a video that explains the cartesian product with visualizations.
Test the concept with the app below. This app will accept image files as ‘layers’ and output all unique combinations of those layers. To use the app start by creating layers, then add images. Press the ‘Combine Layers’ button to calculate the unique combinations.
Thanks for reading. If you enjoyed this post, I invite you to explore more of my site. I write about web development, programming, and other fun stuff.