Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby array group by attribute

irb(main):001:0> aers = %w(a b c d ab bc de abc)
#=> ["a", "b", "c", "d", "ab", "bc", "de", "abc"]

irb(main):002:0> aers.group_by{ |s| s.size }
#=> {1=>["a", "b", "c", "d"], 2=>["ab", "bc", "de"], 3=>["abc"]}

people.group_by { |p| p['age'] }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #ruby #array #group #attribute
ADD COMMENT
Topic
Name
7+3 =