All non-ordered pairs between the elements of an array
Haskell, 29 bytes
f(a:b)=map((,)a)b++f b
f _=[]
Try it online! Example usage: f ["a","b","c"]
yields [("a","b"),("a","c"),("b","c")]
.
With the flag -XTupleSections
this can be shortened to 27 bytes, however the flag would need to be counted:
f(a:b)=map(a,)b++f b
f _=[]
Try it online!
Mathematica, 14 bytes
#~Subsets~{2}&
input
[{"a", "b", "c"}]
Haskell, 25 bytes
f l=[(x,y)|x<-l,y<-l,x<y]
Try it online!
Outer (x
) and inner (y
) loop through the input list and keep the pair (x,y)
only if x < y
.