Coordinates of rectangle with given points lie inside | function to print coordinate of smallest rectangle ; find Xmax and Xmin ; find Ymax and Ymin ; print all four coordinates ; driver program
function printRect ( X , Y , n ) { var Xmax = X . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var Xmin = X . reduce ( ( a , b ) => Math . min ( a , b ) ) ; var Ymax = Y . reduce ( ( a , b ) => Math . max ( a , b ) ) ; var Ymin = Y . reduce ( ( a , b ) => Math . min ( a , b ) ) ; document . write ( " " + Xmin + " " + Ymin + " " + " " ) ; document . write ( " " + Xmin + " " + Ymax + " " + " " ) ; document . write ( " " + Xmax + " " + Ymax + " " + " " ) ; document . write ( " " + Xmax + " " + Ymin + " " + " " ) ; } var X = [ 4 , 3 , 6 , 1 , - 1 , 12 ] ; var Y = [ 4 , 1 , 10 , 3 , 7 , - 1 ] ; var n = X . length ; printRect ( X , Y , n ) ;