Find the coordinates of the fourth vertex of a rectangle with given 3 vertices | Function that return the coordinates of the fourth vertex of the rectangle ; Save the coordinates of the given vertices of the rectangle ; 1 - based indexing ; Driver code
function findFourthVertex ( n , m , s ) { var row = new Map ( ) , col = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < m ; j ++ ) if ( s [ i ] [ j ] == ' ' ) { if ( row . has ( i ) ) row . set ( i , row . get ( i ) + 1 ) else row . set ( i , 1 ) if ( col . has ( j ) ) col . set ( j , col . get ( j ) + 1 ) else col . set ( j , 1 ) } var x , y ; row . forEach ( ( value , key ) => { if ( value == 1 ) x = key ; } ) ; col . forEach ( ( value , key ) => { if ( value == 1 ) y = key ; } ) ; return [ x + 1 , y + 1 ] ; } var s = [ " " , " " , " " ] ; var n = s . length ; var m = s [ 0 ] . length ; var rs = findFourthVertex ( n , m , s ) ; document . write ( rs [ 0 ] + " " + rs [ 1 ] ) ;