This is quite helpful. If we ever meet I owe you each a beer.

In my newbie opinion, Matt Neuburg did a fantastic job above:

> Think of it this way:

> inject(memo) { | memo, enum | block sets memo } => memo

> So memo has three stages:

> 1. Before the first iteration, memo is set to the value of the parameter
> (in parentheses after "inject").

> 2. After each iteration, the result of the block becomes the new value
> of memo.

> 3. When it's all over, the value of memo is the result.

> So it's all about accumulating results into memo. (It is sometimes
> called the accumulator.)

What I'm really trying to get at with this question however, is 
digesting something more like the following (and yes, I know it gets 
slightly more complicated when I introduce a hash..and a map).

def mode(array)
  recur = array.inject(Hash.new(0)) {|k,v| k[v]+=1; k}.sort_by { | (a,b) 
| -b }
  recur.select { | (a,b) | b == recur[0][1] }.map{ |(a,b) | a }
end

This is meant to find the mode of an array, but I can't understand it 
clearly. HELP!

-- 
Posted via http://www.ruby-forum.com/.