When faced with this code test question, I decided to tackle it with the following approach:
function createPattern(){
var result = ''
for (var row = 0; row < 10; row++){
for (var col = 0; col < 10; col++){
if ((row % 3 == 0 && col % 3 == 0) || (row % 3 == 1 && col % 3 == 1) || (row % 3 == 2 && col % 3 == 2)){
result += '1'
} else {
result += '0'
}
if (col == 9){
result += '\n'
}
}
}
console.log(result)
}
Here is the resulting pattern:
1001001001
0100100100
0010010010
1001001001
0100100100
0010010010
1001001001
0100100100
0010010010
1001001001
While this code works, I am interested in exploring more efficient ways to achieve the same output. Any suggestions?