I have an array like this.
@arr = ["Ac", "Ba", "Ca", "Dd", "aC", "bD", "cA", "dD"]
I want to swap the letter if the first one is a capital. In this case, Ac becomes cA, Ba -> aB etc. This becomes like this.
@arr = ["cA", "aB", "aC", "dD", "aC", "bD", "cA", "dD"]
Then I want to find the same item. In this case there are two, cA and dD.
@newarr = ["cA", "dD"]
This is what I have got so far:
@firstarr = @arr.map{|item|
if item[0] =~ /[A-Z]/
item = item[1]+item[0]
else
itme = item
end
}
This gives
@firstarr = ["cA", "aB", "aC", "dD", "aC", "bD", "cA", "dD"]