Skip to content

Instantly share code, notes, and snippets.

@davejlong
Created May 7, 2015 15:22
Show Gist options
  • Save davejlong/d7060775dc52c4342879 to your computer and use it in GitHub Desktop.
Save davejlong/d7060775dc52c4342879 to your computer and use it in GitHub Desktop.
records = [
{ id: "PU525", note: "Foo" },
{ id: "PU525", note: "Bar" },
{ id: "DT525", note: "Hello World" },
{ id: "PU680", note: "Fubar" }
]
[:id, :note].zip(
records.group_by { |record| record[:id] }
.map do |k, v|
[k, v.reduce('') { |memo, h| memo + h[:note] } ]
end
) # =>
# [[:id, ["PU525", "FooBar"]], [:note, ["DT525", "Hello World"]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment