Sha256: 56af22dcc9505ec149f0bab6cbad4da3b2583717f15fd7bde4c3b0bf8ee58e27

Contents?: true

Size: 261 Bytes

Versions: 8

Compression:

Stored size: 261 Bytes

Contents

# frozen_string_literal: true

module Math
  def self.average(values)
    values = values.map { |v| [v, 1] }.to_h unless values.is_a?(Hash)

    values.inject(0) do |sum, vals|
      sum + vals.inject { |a, b| a * b }
    end / values.values.sum.to_f
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
darthjee-core_ext-1.7.4 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.7.3 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.7.2 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.7.1 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.7.0 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.6.2 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.6.1 lib/darthjee/core_ext/math.rb
darthjee-core_ext-1.6.0 lib/darthjee/core_ext/math.rb