In Ruby, you can add two arrays element-wise using the zip
method. Here's the code to add the arrays [*1..3]
and [*4..6]
element-wise to get another 3-element array:
main.rb105 chars7 lines
This will output [5, 7, 9]
, which is the result of adding the two arrays element-wise.
gistlibby LogSnag