Last active
December 27, 2023 22:12
-
-
Save petergi/4e002f0b3426c2a1ae516746ab2aee29 to your computer and use it in GitHub Desktop.
Calculates the distance between two vectors
This file contains hidden or 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
| /** | |
| * Calculates the distance between two vectors. | |
| * | |
| * @param {Array} x - The first vector. | |
| * @param {Array} y - The second vector. | |
| * @return {number} The distance between the two vectors. | |
| */ | |
| function vectorDistance(x, y) { | |
| return Math.sqrt(x.reduce((acc, val, i) => acc + (val - y[i]) ** 2, 0)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment