RosettaCodeData/Task/Dot-product/Groovy/dot-product-1.groovy
2023-07-01 13:44:08 -04:00

4 lines
129 B
Groovy

def dotProduct = { x, y ->
assert x && y && x.size() == y.size()
[x, y].transpose().collect{ xx, yy -> xx * yy }.sum()
}