Last active
August 29, 2019 07:03
-
-
Save horiuchie/b534de18705f882661477deb94a21775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://en.wikipedia.org/wiki/Euclidean_distance | |
const euclideanDistance = R.compose( | |
Math.sqrt, | |
R.sum, | |
R.zipWith(R.compose(x => x * x, R.subtract)) | |
); | |
console.log(euclideanDistance([1, 2], [3, 4])); // [x1, y1], [x2, y2] | |
// 2.8284271247461903 | |
console.log(euclideanDistance([1, 2, 3], [3, 4, 5])); // [x1, y1, z1], [x2, y2, z2] | |
// 3.4641016151377544 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment