Ruby on Rails Friday, August 3, 2012

Botp, thanks for replay, this is solution:


list.inject(Hash.new(0)) { |hash, el| hash[el[:cod]] += el[:val] ; hash }


I want it out:

{"0006"=>120, "0005"=>17, "0004"=>33, "0002"=>27, "0001"=>22}

Thanks for replay again.

On Fri, Aug 3, 2012 at 8:39 AM, botp <botpena@gmail.com> wrote:
On Fri, Aug 3, 2012 at 7:33 PM, Esmerino Jr <jose.esmerino@gmail.com> wrote:
> Thanks for replay, but this solution only remove the duplication of values
> and sum of values duplication?

pls show what output you really want.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment