Group programming languages by their first letter : group_by « Array « Ruby






Group programming languages by their first letter


langs = %w[ java perl python ruby ]
groups = langs.group_by {|lang| lang[0] }
p groups # => {"j"=>["java"], "p"=>["perl", "python"], "r"=>["ruby"]}

 

Related examples in the same category