I'm looking to generate unique combinations of element positions in a JavaScript array.
Here's the array I am working with:
var places = ['x', 'y', 'z'];
The combinations I want are: [0,1], [0,2], [1,2].
Currently, I am using the following code which is functional but slightly cumbersome:
for (var i = 0; i < places.length; i++) {
for (var j = 0; j < places.length; j++) {
if ((j > i) && (j != i)) {
console.log(i, j);
}
}
}
Is there a cleaner or more efficient way to achieve this?