Skip to content

Instantly share code, notes, and snippets.

@horiuchie
Last active August 29, 2019 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horiuchie/b534de18705f882661477deb94a21775 to your computer and use it in GitHub Desktop.
Save horiuchie/b534de18705f882661477deb94a21775 to your computer and use it in GitHub Desktop.
// 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