Ruby - Identify and Update Duplicates in Array with Index Value

I have an array which may or may not include duplicates, but no nil or "" values.

array = ["Ballerina", "Lagoon", "Black", "Space", "Golden", "Lagoon"]

This is really the closest I've gotten to solving the problem, but the problem here is that I don't know the duplicates, so its not really valid:

array.each_with_index.map {|value, index| array[index] == "Lagoon" ? index : ""}.uniq

What I'm looking to return is for any duplicates in the array to concatenate the index value onto the end of the array value. So the end result would be:

array = ["Ballerina", "Lagoon 1", "Black", "Space", "Golden", "Lagoon 5"]

Thanks



Comments

Popular posts from this blog

I get wrong characters when retreiving the message body of an email using TIdIMAP4.UIDRetrieveTextPeek2()

How to drop the all the 1's in a correlation matrix

Today Walkin 14th-Sept