Call uniq to remove the duplications : uniq « Array « Ruby






Call uniq to remove the duplications


shopping_list = %w[ cheese bread crackers potatoes carrots cheese ]
shopping_list.uniq! # => ["cheese", "bread", "crackers", "potatoes", "carrots"]

 

Related examples in the same category

1.Unique Elements
2.Stripping Duplicate Elements from an Array