I have an array of objects that looks like that
[{ property1: 10 }, { property1: 13 }, { property1: 15 }, { property2: 2 }]
I want to write a function that would give me in an object all the indexes of comparison (only from left to right) of those properties if they are the same:
{ property1: [[0, 1], [0, 2], [1, 2]] }
For example, if my input array looks like that
[{ property1: 10 }, { property1: 13 }, { property2: 15 }, { property2: 2 }]
The result would be
{
property1: [[0, 1]],
property2: [[2, 3]]
}
If there are 4 same properties (the length of the input array will never be bigger than 4):
[{ property1: 10 }, { property1: 13 }, { property1: 15 }, { property1: 2 }]
The result should look like
{
property1: [[0, 1], [0,2], [0,3], [1,2], [1,3], [2,3]]
}
Keys property1 are the same so I get their indexes (0, 1) and property2 keys are the same so I get their indexes (1, 2). Here there's only one combination possible as there are only 2 values that are the same for each but if there are more values that are the same I don't get how can I have the combinations of indexes. For the first example, I have 3 same keys (property1) so in case I need to know the combination of indexes between those 3, but only from left to right so (0,1), (0,2), and (1,2). I can see how to count the properties that are the same or return the indexes of the same properties but I don't see how can I get the possible combinations of indexes.