Find a way to fill matrix with 1 ' s ▁ and ▁ 0' s in blank positions | Javascript implementation of the approach ; Function to generate and print the required matrix ; Replace the ' . ' ; Toggle number ; For each row , change the starting number ; Driver code
const N = 2 ; const M = 2 ; function Matrix ( a ) { let ch = ' ' ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == ' ' ) a [ i ] [ j ] = ch ; ch = ( ch == ' ' ) ? ' ' : ' ' ; document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; if ( i % 2 == 0 ) ch = ' ' ; else ch = ' ' ; } } let a = [ [ ' ' , ' ' ] , [ ' ' , ' ' ] ] ; Matrix ( a ) ;