Class: Pcalci::Pcalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/pcalci/pcalculator.rb

Class Method Summary collapse

Class Method Details

.profit(bought, sold, type) ⇒ Object



4
5
6
7
8
# File 'lib/pcalci/pcalculator.rb', line 4

def self.profit bought, sold, type
	avg_bought = bought.inject(0) {|sum,(amount,price)| sum + amount*price }
	avg_sold = sold.inject(0) {|sum,(amount,price)| sum + amount*price }
	avg_sold - avg_bought
end