How to fill an array like this on a table?

enter image description here

Here is my code and then I don’t know what to do:

var arr = []; var rows = 7; var cols = 7; for (var i = 0; i < rows; i++) { arr[i] = []; for (var j = 0; j < cols; j++) { arr[i][j] = i; if (i == j ||) { arr[i][j] = 1; } else { arr[i][j] = 0; } } } 
  • 2
    Do you perform any tasks? This is not the first question to fill the array. And each time it's a crazy code inside. especially so that they do not ask SO, but what did you try yourself? In general, what is the practical meaning of this question? - Alexey Shimansky
  • Yes, truly doing the job! but I’m gonna do it for the first time, I don’t know how to do it, maybe I'm stupid)), it's hard for me to do something - brin gonor
  • How many minutes did you try to do before writing to SO? - Alexey Shimansky
  • yes not many 10-15 minutes where so - brin gonor
  • 3
    No words. Decent. 1) You are not given assignments that do not explain how to solve. 2) After 10 minutes to run with a trifle to the uncles - either throw it or do it, or learn with this attitude. - user207618

1 answer 1

 var arr = []; var rows = 7; var cols = 7; for (var i = 0; i < rows; i++) { arr[i] = []; for (var j = 0; j < cols; j++) { arr[i][j] = i; if (i == j || i == (rows - 1) / 2 || j == (cols - 1) / 2 || i == (cols - j - 1)) { arr[i][j] = 1; } else { arr[i][j] = 0; } } }