Report abuse

Quiz


			
http://www.rubyquiz.com/quiz131.html

Answer


			
class Symbol
  def to_proc
    Proc.new {|o| o.send(self)}
  end
end

class Array
  def sum
    inject(0) do |c,x|
      x + c
    end
  end

  def maximum_sub_array
    q = []
    1.upto(length) do |start|
      length.downto(1) do |finish|
        q << self[start..finish]
      end
    end
    q.sort_by(&:sum).last
  end
end

puts [-1, 2, 5, -1, 3, -2, 1].maximum_sub_array.inspect