Это чисто Ruby решение.
arr = [
[
{:user=>"Maria",
:alerts=>{:rfc=>"This rfc is invalid"}},
{:user=>"Juan",
:alerts=>{:email=>"This email is invalid"}}
],
[
{:user=>"Maria",
:alerts=>{:income_in_the_mean=>true, :credit_in_the_mean=>true}},
{:user=>"Juan",
:alerts=>{:income_in_the_mean=>false, :credit_in_the_mean=>true}}
]
]
arr.flatten.group_by { |h| h[:user] }.map do |user,a|
{ user: user, alerts: a.reduce({}) { |h,g| h.merge(g[:alerts]) } }
end
#=> [{:user=>"Maria",
# :alerts=>{:rfc=>"This rfc is invalid", :income_in_the_mean=>true,
# :credit_in_the_mean=>true}},
# {:user=>"Juan",
# :alerts=>{:email=>"This email is invalid", :income_in_the_mean=>false,
# :credit_in_the_mean=>true}}]
Примечание:
arr.flatten.group_by { |h| h[:user] }
#=> {"Maria"=>[{:user=>"Maria", :alerts=>{:rfc=>"This rfc is invalid"}},
# {:user=>"Maria", :alerts=>{:income_in_the_mean=>true,
# :credit_in_the_mean=>true}}],
# "Juan" =>[{:user=>"Juan", :alerts=>{:email=>"This email is invalid"}},
# {:user=>"Juan", :alerts=>{:income_in_the_mean=>false,
# :credit_in_the_mean=>true}}]}
arr
банкаконечно, любого размера.