Iterate all possible 2-element subarrays (order matters) : permutation « Array « Ruby






Iterate all possible 2-element subarrays (order matters)

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

 

Related examples in the same category