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

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)