I'm not really sure how to title this one, so if someone knows better, be my guest.
Basically, using nested for-loops, I'm trying to generate a 2-d array where each row starts at one number higher than the previous row, and then loops around on itself, so that the total of each row remains equal. Let me rather just show you what I mean:
[
[1, 2, 3], // 1 + 2 + 3 = 6
[2, 3, 1], // 2 + 3 + 1 = 6
[3, 1, 2], // 3 + 1 + 2 = 6
]
See how every row is just 1, 2, 3 but every following row starts at i + 1 and when it reaches 3 it "resets" back to 1? That's what I'm trying to achieve.
Here's what I have so far:
const grid = []
const gridSize = 3
for(let i = 0; i < gridSize; i++) {
const row = []
for(let j = 0; j < gridSize; j++) {
row.push(/* what goes here?? this is where I get stuck */)
}
grid.push(row)
}