What is that ?

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..]

:slight_smile:

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?

right :slight_smile: