Find the remaining vertices of a square from two given vertices | Function to find the remaining vertices of a square ; Check if the x - coordinates are equal ; Check if the y - coordinates are equal ; If the the given coordinates forms a diagonal of the square ; Otherwise ; Square does not exist ; Given two vertices
function findVertices ( x1 , y1 , x2 , y2 ) { if ( x1 == x2 ) { document . write ( ( x1 + y2 - y1 ) + " " + y1 + " " ) ; document . write ( ( x2 + y2 - y1 ) + " " + y2 ) ; } else if ( y1 == y2 ) { document . write ( x1 + " " + ( y1 + x2 - x1 ) + " " ) ; document . write ( x2 + " " + ( y2 + x2 - x1 ) ) ; } else if ( Math . abs ( x2 - x1 ) === Math . abs ( y2 - y1 ) ) { document . write ( x1 + " " + y2 + " " ) ; document . write ( x2 + " " + y1 ) ; } else document . write ( " " ) ; } let x1 = 1 , y1 = 2 ; let x2 = 3 , y2 = 4 ; findVertices ( x1 , y1 , x2 , y2 ) ;