Does anyone can define this function ? * range.inject(Hash.new(0)){|h,e| h[e] += 1; h} * range is array of integers like: [1,22,12,8,45,3,etc..] :) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
alexey.Creopolis wrote:> Does anyone can define this function ? > > * range.inject(Hash.new(0)){|h,e| h[e] += 1; h} * > > range is array of integers like: [1,22,12,8,45,3,etc..]It''s a counter, it will return a hash with the entries in range as keys and the number of occurences of each entry as values. So if range is [1, 1, 2, 3] it will return { 1 => 2, 2 => 1, 3 => 1 } Is this what you wanted to know? -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
right :) On 9 сент, 14:16, Jacob Atzen <ja...-4U2y0bnePT5NzRJJ8cAMrg@public.gmane.org> wrote:> alexey.Creopolis wrote: > > Does anyone can define this function ? > > > * range.inject(Hash.new(0)){|h,e| h[e] += 1; h} * > > > range is array of integers like: [1,22,12,8,45,3,etc..] > > It''s a counter, it will return a hash with the entries in range as keys > and the number of occurences of each entry as values. So if range is [1, > 1, 2, 3] it will return { 1 => 2, 2 => 1, 3 => 1 } > > Is this what you wanted to know? > > -- > Cheers, > - Jacob Atzen--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---