How to check in 2d array if four elements in row and column are the same?

Viewed 2842

I'm trying to get a nested forEach loop, that find a pair of four in a two dimensional array.

Here a example how my array looks like:

[0, 0, 0, 0, 0],
[0, 2, 0, 0, 0],
[0, 1, 2, 0, 0],
[0, 1, 2, 2, 0],
[1, 2, 1, 1, 2],

It should ignore the 0 and only find horizontal, vertical and diagonal pairs of four of entries with '1' or '2'.

Does anybody have any suggestion?

4 Answers
Related