Grids to store the possible grids
let gridTest1 = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( 1001 ) ) ; let gridTest2 = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( 1001 ) ) ; createGrid ( gridTest1 , true , N , M ) ; createGrid ( gridTest2 , false , N , M ) ; if ( testGrid ( gridTest1 , grid , N , M ) ) { document . write ( " " ) ; printGrid ( gridTest1 , N , M ) ; } else if ( testGrid ( gridTest2 , grid , N , M ) ) { document . write ( " " ) ; printGrid ( gridTest2 , N , M ) ; } else { document . write ( " " ) ; } }