I have to sort this
ary = [[5, "e", "2"], [2, "r", "="], [2, "y", "2"], [2, "h", "="]]
to obtain :
# => [[5, "e", "2"], [2, "y", "2"], [2, "h", "="], [2, "r", "="]]
If the last element (index 2) is equal to "=" it must be after the array which has the same first element even if the letter is before. Something like this :
ary.each_with_index do |array, index|
if ary[index][2] == "=" && ary[index][0] == ary[index +1][2]
a = ary[index]
b = ary[index +1]
ary[index] = b
ary[index+1] = a
end
end
"="? What aboutary = [[2, "e", "2"], [2, "e", "10"]]? Please clarify by editing (rather than posting a comment).