Returning unique items of an Array
I would like to know how to get combanations of any Array without repeats of same elements in a different order.
The array is made of object properties and could have variable number of elements.
In other words if I have an Array of for example 2 elements
[a, b]
I want to receive 3 new sub arrays
2)
3) [a, b]
I don't want to receive [b, a] as that has the same elements as [a, b] just in a different order.
Well if there just 2 elements in the array then that's easy enough but when there are more then it's beyond me!!
An Array of for example 4 elements
[a, b, c, d]
would need to produce a new array made of the following 15 sub arrays
2)
3)
4)
5) [a, b]
6) [a, c]
7) [a, d]
😎 [b, c]
9) [b, d]
10) [c, d]
11) [a,b, c]
12) [a, b, d]
13) [a, c,d]
14) [b, c, d]
15) [a, b, c, d]
A 5 element array would give me 24 sub arrays and so on.
I have tried numerous ways with diddlysquat results ![]()
Slice, splice and all things nice !!
If any of you could share this trade secret with me, I would much appreciate it.
Trevor
