Created
January 4, 2009 07:03
-
-
Save nanodeath/43018 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def sum | |
inject {|sum, n| sum + (n || 0)} || 0 | |
end | |
# Sum two numeric arrays | |
def add(other_array) | |
raise ArgumentError unless other_array.is_a? Array | |
(length > other_array.length ? zip(other_array) : other_array.zip(self)).collect(&:sum) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment