Artificial intelligent assistant

Math behind a Javascript implementation of shortest vector distance I got a implementation of finding the shortest vector distance, but would like to know the actual equation for this implementation. function closestLocation(targetLocation, locationData){ function vectorDistance(dx, dy){ return Math.sqrt(dx * dx + dy * dy); } function locationDistance(location1, location2){ var dx = location1.latitude - location2.latitude, dy = location1.latitude - location2.longitude; return vectorDistance(dx, dy); } return locationData.reduce(function(prev, curr){ var prevDistance = locationDistance(targetLocation, prev), currDistance = locationDistance(targetLocation, curr); return (prevDistance < currDistance) ? prev : curr; }); } Any that can help with that?

So basically if you have two points in 2D space

$p_1=\left(x_1,y_1\right)$ and $p_2=\left(x_2,y_2\right)$.

Its distance, as calculated in this Java code, is the Euclidean distance

$d=\sqrt{\left(x_1-x_2\right)^2+\left(y_1-y_2\right)^2}$

In parts, the function _locationDistance_ computes the parts inside the parenthesis in the square root and the function _vectorDistance_ computes _d_.

It is not clear from your piece of code but I suspect that the variables _prev_ and _curr_ will be part of a loop that tries to compare a given location ( _targetLocation_ ) with a set of other locations ( _locationData_ ) and keep always the minimum in _prev_ comparing with the new ones in _curr_. And that's what is done in the reduce statement.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ba339415be21f35110419e4719e7636c