Last active
December 23, 2017 09:08
-
-
Save skiano/91d794e0484051c050c734cd5b63c26c to your computer and use it in GitHub Desktop.
n-dimension distance
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
// not really about performance | |
// but fun to make it one line | |
// this discussion looked interesting re estimating | |
// https://stackoverflow.com/questions/3693514/very-fast-3d-distance-check | |
const distance = (a, b) => Math.sqrt(a.reduce((total, _, i) => total + Math.pow(b[i] - a[i], 2), 0)) | |
const _2d_ = distance([1, 2], [0, 4]) | |
const _3d_ = distance([1, 2, 3], [0, 4, 5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment