Hello guys,

I have been working with ranking algorithm, wich collects the smallest
numbers chronologically. but i couldn't make it work.

Here is the code.


module Enumerable
 def min_n(n, &block)
    block = Proc.new { |x,y| x <=> y} if block == nil
    stable = StortedArray.new(&block)
    each do |x|
      stable << x if stable.size < n or block.call(x, stable[-1]) == -1
      stable.pop until stable.size <=n
    end
    return stable

  end

end

m = [1,5,2,8,7,9,10,100,50]
m.min_n(4)


I would be more than glad to get your feedback/suggestions of how to
make it work.

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