I have three arrays. The arrays all have the same size and contain the same elements. However, the three arrays must not be in the same order. How do I verify that the elements are not in the same order?
Here's how I've implemented it:
all_elements_equal = true
array1.zip(array2, array3) do |first, second, third|
if first != second && second != third && first != third
all_elements_equal = false
end
end
If all_elements_equal is false, presumably the arrays are not in the same order. However, there is a possibility that this will not be the case if only one of the arrays is different and the other two are identical.
So, my question is, how do I make the test stronger, and is there a more elegant way of implementing the code? Full disclosure: I am new to Ruby.