Browse | Submit A New Snippet | Create A Package

 

[ 2 , 4 ] * [ 5, 5 ]

Type:
Function
Category:
Math Functions
License:
GNU General Public License
Language:
Ruby
 
Description:
Array multiplication

Versions Of This Snippet::

Rodrigo Bermejo
Snippet ID Download Version Date Posted Author Delete
13812006-01-20 03:33Rodrigo Bermejo
Changes since last version::
Thanks to Robert Gustavsson for his observation
The alen and blen were not needed
251.02004-01-05 23:59Rodrigo Bermejo

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1

class Array
   def *(a)
       n    = Array.new
       [ self.length, a.length].max.
       times do |x|           
           n[x] = ( self[x] || 0 ) * ( a[x] || 0 )
       end
       n
   end
end 
#[ 2,4,4 ]  *  [ 5,5 ]
# =>[10,20,0]
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..