Function to calculate Euclidean distance
function find ( x , y , p ) { let mind = 0 ; for ( let i = 0 ; i < p . length ; i ++ ) { let a = p [ i ] [ 0 ] , b = p [ i ] [ 1 ] ; mind += Math . sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) ) ; } return mind ; }