Skip to content

Instantly share code, notes, and snippets.

@rapimo
Created July 4, 2012 09:32
Show Gist options
  • Save rapimo/3046359 to your computer and use it in GitHub Desktop.
Save rapimo/3046359 to your computer and use it in GitHub Desktop.
add two arrays
class Array
# [1,2,3].add [1,2,3] => [2, 4, 6]
def add (other)
self.zip(other).map{|a| a.inject(0){|s,n| s+=n || 0;s }}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment