Skip to content

Instantly share code, notes, and snippets.

@thiagovsk
Created Feb 6, 2017
Embed
What would you like to do?
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