Sha256: ee1d8b6df55a6dee19fe2eed946540cf6a85a27c18f383fc45aff451d48e5282

Contents?: true

Size: 272 Bytes

Versions: 3

Compression:

Stored size: 272 Bytes

Contents

class Array
  def median
    if self.length != 0
      copy = self.sort

      if copy.length % 2 == 0
        (copy[copy.length / 2 - 1] + copy[copy.length / 2]) / 2.0
      else
        copy[copy.length / 2]
      end
    else
      nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rstat-0.1.2 lib/rstat/core_ext/array/descriptive_statistics/location/median.rb
rstat-0.1.1 lib/rstat/core_ext/array/descriptive_statistics/location/median.rb
rstat-0.1.0 lib/rstat/core_ext/array/descriptive_statistics/location/median.rb