Check in all four possible directions
let temp1 = Distance ( arr , i + 1 , j ) ; let temp2 = Distance ( arr , i - 1 , j ) ; let temp3 = Distance ( arr , i , j + 1 ) ; let temp4 = Distance ( arr , i , j - 1 ) ;