Class: PangrammicSurplus::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/pangrammic_surplus/vector.rb

Class Method Summary collapse

Class Method Details

.add(*v) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/pangrammic_surplus/vector.rb', line 4

def add(*v)
  first = v.first
  first.inject({}) do |hash, (k, _)|
    sum = v.map { |h| h[k] }.inject(:+)
    hash.merge(k => sum)
  end
end

.subtract(a, b) ⇒ Object



12
13
14
15
# File 'lib/pangrammic_surplus/vector.rb', line 12

def subtract(a, b)
  _b = b.inject({}) { |h, (k, v)| h.merge(k => -v) }
  add(a, _b)
end