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”]
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”]
Hi,
You could map the array to the second entry of each element and then
apply the uniq method:
b = a.map{|entry| entry[1]}.uniq
puts b
Jacques
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs