Michael Pavling, thanks for reply.
Okay, i agree that is a array of hash : list.class => Array end
list.last.class => Hash.
But your solution only removes duplication and the sum of :val ?
Tom Meinlschmid, thanks for reply.
Not a test for job seekers :)
Solution:
list.inject(Hash.new(0)) { |hash, el| hash[el[:cod]] += el[:val] ; hash }
On Fri, Aug 3, 2012 at 4:58 AM, Tom Meinlschmidt <[email protected]>wrote:
> saw something similar somewhere as a test for job seekers :)
>
> so don't know if someone will help you as it's not so hard to solve
>
> tom
>
> On Aug 1, 2012, at 15:25 , Esmerino Costa <[email protected]> wrote:
>
> > I have a hash like so:
> >
> > list=[
> > {:cod => "0001", :name => "name1", :val => 10},
> > {:cod => "0001", :name => "name1", :val => 12},
> > {:cod => "0002", :name => "name2", :val => 13},
> > {:cod => "0002", :name => "name2", :val => 14},
> > {:cod => "0002", :name => "name2", :val => 14},
> > {:cod => "0004", :name => "name4", :val => 16},
> > {:cod => "0004", :name => "name4", :val => 16},
> > {:cod => "0004", :name => "name4", :val => 17},
> > {:cod => "0005", :name => "name5", :val => 17},
> > {:cod => "0005", :name => "name5", :val => 17},
> > {:cod => "0005", :name => "name5", :val => 17},
> > {:cod => "0006", :name => "name6", :val => 110},
> > {:cod => "0006", :name => "name6", :val => 10},
> > ]
> > What I would like to learn how to do is how to remove a record if it is
> duplicate end sum values :val.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected].
> > To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/SJr0rc22ScgJ.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
> --
>
> ===============================================================================
> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
>
> www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
>
> ===============================================================================
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.