Okay, I made it kinda works, clunky and ugly though...


class Array
  def max
    max = 0;
    self.each{ |i| max = i>max ? i : max }
    max
  end
  def min
    min = 9999;
    self.each{ |i| min = i<min ? i : min }
    min
  end
  def depthen
    base_depth = self.min
    range = [0,0]
    in_flag, out_flag = false, false
    self.each_index{ |i|
      if self[i]>base_depth && !in_flag
        in_flag = true;
        range[0] = i
      end
      if self[i] <= base_depth && !out_flag
        out_flag = true
        range[1] = i-1
      end
    }
    to_insert = self.slice!(eval(range.join('..')))
    to_insert.depthen if to_insert.max>to_insert.min
    self.insert( range[0], to_insert )
  end
end

p [2,3,3,5,4,4].depthen => [2,[3,3,[[5],4,4]]]

I will be really thankful if anybody could help me improve this monster 
with nice ruby tricks.

Thank you in advance,
Chris.
-- 
Posted via http://www.ruby-forum.com/.