Skip to content

Instantly share code, notes, and snippets.

@thiagovsk
Created February 6, 2017 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagovsk/aa989e73630c3163c774f3e1444f672e to your computer and use it in GitHub Desktop.
Save thiagovsk/aa989e73630c3163c774f3e1444f672e to your computer and use it in GitHub Desktop.
ajudando o luiz a fazer group_by
a = [ {x: 'Abril/17', y: 10}, {x: 'Abril/17', y: 5}, {x: 'Abril/17', y: 2}, {x: 'Dezembro/17', y: 12}, ]
luiz = a.group_by{ |hash| hash[:x] }.map do |k,v|
{:x => k, :y => v.map{ |hash| hash[:y] }.inject(:+)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment