Iterate all possible 2-element subsets (order does not matter) : combination « Array « Ruby






Iterate all possible 2-element subsets (order does not matter)

a = [1,2,3]
a.combination(2) {|x| print x }  # Prints "[1, 2][1, 3][2, 3]"

 

Related examples in the same category