Removing code duplication in ruby
Is there a cleaner way to write this ? I don't like that code duplication.
def add_array(a,b)
if a.size > b.size then
a.map.with_index{ |m,i|if i != 0 then m + b[i].to_i else m end}
else
b.map.with_index{ |m,i|if i != 0 then m + a[i].to_i else m end}
end
end
Feel free to comment / criticize and express your imagination!
Thanks.
No comments:
Post a Comment