Skip to content
Advertisement

Calculating Euclidean Distance

I have the code below to calculate Euclidean Distance. however, my function does basically nothing. It gives no output and not even an error, it just runs and finishes.

JavaScript

Advertisement

Answer

Have you called the function?

JavaScript

Output:

JavaScript

For longer lists, you can also do this faster by summing a generator expression instead:

JavaScript

Or you could use math.dist (as pointed out in comments) which is significantly faster still:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement