lib/powercore/array.rb
# Calculates the median of the elements.
Calculates the median of the elements.
Calculates the median of the elements .
def median
    return nil if self.empty?
    sorted = self.sort
    size = self.size
    if size % 2 == 1
      sorted[size / 2]
    else
      (sorted[(size - 1) / 2] + sorted[size / 2]) / 2.0
    end
  end
def median return nil if self . empty? sorted = self . sort size = self . size if size % 2 == 1 sorted [ size / 2 ] else ( sorted [ ( size - 1 ) / 2 ] + sorted [ size / 2 ] ) / 2.0 end end
Calculates the median of the elements.
Calculates the median of the elements .