Provide some helpers for array math These will only work on arrays of number values
Get the average value for an array
# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 10 def average inject(&:+) / length end
Perform division
If provided with an array, will divide all values
If provided with an integer, will divide all values by that value
# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 17 def divide(arr) do_math(arr) do |a,b| a.to_f / b end end
Perform multiplication
If provided with an array, will multiply all values
If provided with an integer, will multiply all values by that value
# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 26 def mult(arr) do_math(arr) do |a,b| a * b end end
# File lib/openshift-origin-node/utils/cgroups/monitored_gear.rb, line 33 def do_math(arr) unless arr.is_a?(Array) arr = [arr] * length end zip(arr).map{|x| yield x.first,x.last } end