There might be a better way to check for squares. Basically you are always getting the data and putting it in to 9 arrays. So at its simplest you want to put these in to arrays and then check them all.

How about we have a function that that takes the x,y and gives us a number that tells us which array something should be in? For rows it's easy (x,y) => x. For columns also easy (x,y) => y. For squares it's a little different - you were mostly there though: (x, y) => 3 * Math.floor(x / 3) + Math.floor(y/3)

basically you divide and floor it to get x and y to 0,1 or 2. Then you multiply one by 3 to basically use base3 numbers.

you'd end up with something like the below (excuse any minor errors and messiness - I just did this quick):

you could make this a bit better by just flattening the data and using a utility like lodash's groupBy. Then you can do something like withIndexAsXY = (fn, index) => fn(index % 9, Math.floor(index / 9)); and use the above functions on flattened data like:

There might be a better way to check for squares. Basically you are always getting the data and putting it in to 9 arrays. So at its simplest you want to put these in to arrays and then check them all.

How about we have a function that that takes the x,y and gives us a number that tells us which array something should be in? For rows it's easy (x,y) => x. For columns also easy (x,y) => y. For squares it's a little different - you were mostly there though: (x, y) => 3 * Math.floor(x / 3) + Math.floor(y/3)

basically you divide and floor it to get x and y to 0,1 or 2. Then you multiply one by 3 to basically use base3 numbers.

you'd end up with something like the below (excuse any minor errors and messiness - I just did this quick):

you could make this a bit better by just flattening the data and using a utility like lodash's groupBy. Then you can do something like withIndexAsXY = (fn, index) => fn(index % 9, Math.floor(index / 9)); and use the above functions on flattened data like:

which may seem more complicated - but it means things have become more reusable