Module: JekyllRecker::Math

Included in:
Generators::Stats
Defined in:
lib/jekyll_recker/math.rb

Overview

Math Module

Instance Method Summary collapse

Instance Method Details

#average(numlist) ⇒ Object



6
7
8
9
# File 'lib/jekyll_recker/math.rb', line 6

def average(numlist)
  calc = numlist.inject { |sum, el| sum + el }.to_f / numlist.size
  calc.round
end

#occurences(keys, targets) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/jekyll_recker/math.rb', line 15

def occurences(keys, targets)
  results = Hash.new(0)
  targets.each do |target|
    results[target] += 1 if keys.include? target
  end
  results
end

#total(numlist) ⇒ Object



11
12
13
# File 'lib/jekyll_recker/math.rb', line 11

def total(numlist)
  numlist.inject(0) { |sum, x| sum + x }
end