Sha256: c7a3fca2ac2e4b2ef0334412a093ae25dcb9b055e21cb0b27ac48ec075099206

Contents?: true

Size: 321 Bytes

Versions: 2

Compression:

Stored size: 321 Bytes

Contents

module Enumerable
  unless method_defined?(:median)
    def median(*args, &block)
      if respond_to?(:scoping) && !block
        scoping { @klass.median(*args) }
      else
        sorted = map(&block).sort
        len = sorted.length
        (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_median-0.2.2 lib/active_median/enumerable.rb
active_median-0.2.1 lib/active_median/enumerable.rb