Dot product: Difference between revisions

→‎{{header|Ruby}}: use sum method
(→‎{{header|Raku}}: create a subroutine)
(→‎{{header|Ruby}}: use sum method)
Line 2,876:
def dot_product(other)
raise "not the same size!" if self.length != other.length
self.zip(other).inject(0)sum {|dp, (a, b)| dp += a*b}
end
end
1,149

edits