Created
August 5, 2012 04:11
-
-
Save hoshinotsuyoshi/3261620 to your computer and use it in GitHub Desktop.
配列同士の中身の掛け算(適当メモ)
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 | |
def *(arr) | |
self.each_with_index.map{|e,i| e*arr[i] } | |
end | |
end | |
[3,4,5] * [6,-7,8] #=> [18,-28,40] | |
[[1,2],[3,4]] * [[-2,-3],[-3,-4]] #=> [[-2, -6], [-9, -16]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment