Dot product: Difference between revisions
Content added Content deleted
(→{{header|Raku}}: create a subroutine) |
(→{{header|Ruby}}: use sum method) |
||
Line 2,876: | Line 2,876: | ||
def dot_product(other) |
def dot_product(other) |
||
raise "not the same size!" if self.length != other.length |
raise "not the same size!" if self.length != other.length |
||
zip(other).sum {|a, b| a*b} |
|||
end |
end |
||
end |
end |