Created
July 4, 2012 09:32
-
-
Save rapimo/3046359 to your computer and use it in GitHub Desktop.
add two arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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