Module: Digiproc::CoreExtensions::ArrayExtension::Sum

Defined in:
lib/extensions/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#plus(arr) ⇒ Object

Add two arrays element by element. They must be the same size myArray.plus(anotherArr) # => Array (same size as the input)

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
# File 'lib/extensions/core_extensions.rb', line 22

def plus(arr)
    raise ArgumentError.new("sizes must be equal") if self.size != arr.size
    output = []
    self.each_with_index do |o,i|
        output << o + arr[i]
    end
    output
end