Array and unique item

If I have a multiple array:

a = [[1, “black”, 3], [2, “blue”, 3], [3, “black”, 3], [4, “red”, 3],
[5, “”, 3]]

How can I gen unique colors from it, like this:

b = [“black”,“blue”,“red”]


You could map the array to the second entry of each element and then
apply the uniq method:

b ={|entry| entry[1]}.uniq
puts b


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs