Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Last active January 31, 2016 07:16
Show Gist options
  • Save iboss-ptk/083c531ed4edf8960714 to your computer and use it in GitHub Desktop.
Save iboss-ptk/083c531ed4edf8960714 to your computer and use it in GitHub Desktop.
def dotProduct(vector1: Vector[Double], vector2: Vector[Double]) =
vector1.zip(vector2)
.map(v => v._1 * v._2)
.reduce((acc, curr) => acc + curr)
val vector1 = Vector(1.7, 2.3, 4.0)
val vector2 = Vector(2.4, 1.3, 5.1)
dotProduct(vector1, vector2) // => 27.47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment