Skip to main content
fixed initial input data array
Source Link
# ruby syntax

 def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else  
      if obj2[1].nil?
        if obj1[1] == obj2[0]
          return -1
        else 
          return obj1[1] <=> obj2[0]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      if obj1[1].nil?
        if obj1[0] == obj2[1]
          return 1
        else 
          return obj1[0] <=> obj2[1]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], 
 [nil, 3]     [1, [nil2], 
 4]      [2, [nilnil], 
 5]      [3, [nilnil], 
 6]      [4, [nilnil], 
 7]      [5, nil],
       [3[nil, nil]3], 
 [4      [nil, nil]4], 
 [2      [nil, nil]5], 
 [1      [nil, 2]6], 
 [5      [nil, nil]7],
       [6, 8],
       [7, 9],
       [8, nil], 
 [7, 9],     [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
# ruby syntax

 def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else  
      if obj2[1].nil?
        if obj1[1] == obj2[0]
          return -1
        else 
          return obj1[1] <=> obj2[0]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      if obj1[1].nil?
        if obj1[0] == obj2[1]
          return 1
        else 
          return obj1[0] <=> obj2[1]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
# ruby syntax

 def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else  
      if obj2[1].nil?
        if obj1[1] == obj2[0]
          return -1
        else 
          return obj1[1] <=> obj2[0]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      if obj1[1].nil?
        if obj1[0] == obj2[1]
          return 1
        else 
          return obj1[0] <=> obj2[1]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], 
       [1, 2], 
       [2, nil], 
       [3, nil], 
       [4, nil], 
       [5, nil],
       [nil, 3], 
       [nil, 4], 
       [nil, 5], 
       [nil, 6], 
       [nil, 7],
       [6, 8],
       [7, 9],
       [8, nil], 
       [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
added 297 characters in body
Source Link
# ruby syntax

 def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else  
      if obj2[1].nil?
        if obj1[1] == obj2[0]
          return -1
        else 
          return obj1[1] <=> obj2[0]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      if obj1[1].nil?
        if obj1[0] == obj2[1]
          return 1
        else 
          return obj1[0] <=> obj2[1]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
# ruby syntax

def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else 
      if obj2[1].nil?
        return obj1[1] <=> obj2[0]
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      return obj1[0] <=> obj2[1]
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
# ruby syntax

 def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else  
      if obj2[1].nil?
        if obj1[1] == obj2[0]
          return -1
        else 
          return obj1[1] <=> obj2[0]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      if obj1[1].nil?
        if obj1[0] == obj2[1]
          return 1
        else 
          return obj1[0] <=> obj2[1]
        end
      else
        return obj1[1] <=> obj2[1]
      end
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
added 47 characters in body
Source Link
# ruby syntax

def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else 
      if obj2[1].nil?
        return obj1[1] <=> obj2[0]
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      return obj1[0] <=> obj2[1]
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else 
      if obj2[1].nil?
        return obj1[1] <=> obj2[0]
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      return obj1[0] <=> obj2[1]
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
# ruby syntax

def compare_them (obj1, obj2)
  if obj1[0].nil? 
    if !obj2[0].nil?
      return obj1[1] <=> obj2[0]
    else 
      if obj2[1].nil?
        return obj1[1] <=> obj2[0]
      else
        return obj1[1] <=> obj2[1]
      end
    end
  else
    if obj2[0].nil?
      return obj1[0] <=> obj2[1]
    else
      return obj1[0] <=> obj2[0]  
    end
  end
end

foo = [[nil, 1], [nil, 3], [nil, 4], [nil, 5], [nil, 6], [nil, 7], 
       [3, nil], [4, nil], [2, nil], [1, 2], [5, nil], [6, 8], 
       [8, nil], [7, 9], [9, 10]]

foo.sort { |a1,a2| compare_them(a1, a2) }
Source Link
Loading