Sum of Manhattan distances between all pairs of points | Return the sum of distance between all the pair of points . ; for each point , finding distance to rest of the point ; Driver code
function distancesum ( x , y , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ; return sum ; } let x = [ - 1 , 1 , 3 , 2 ] ; let y = [ 5 , 6 , 5 , 3 ] ; let n = x . length ; document . write ( distancesum ( x , y , n ) ) ;