The Christmas lights panel ๐โจ in the workshop has been a total success. But the elves want to go one step further: now they want to detect whether there is a line of 4 lights of the same color also on a diagonal.
The panel is still a matrix where each cell can be:
'.' โ light off'R' โ red light'G' โ green lightNow your function must return true if there is a line of 4 lights of the same color that are on and aligned, whether horizontally โ, vertically โ or diagonally โโ.
hasFourInARow([
['R', '.', '.', '.'],
['.', 'R', '.', '.'],
['.', '.', 'R', '.'],
['.', '.', '.', 'R']
])
// true โ there are 4 red lights in a โ diagonal
hasFourInARow([
['.', '.', '.', 'G'],
['.', '.', 'G', '.'],
['.', 'G', '.', '.'],
['G', '.', '.', '.']
])
// true โ there are 4 green lights in a โ diagonal
hasFourInARow([
['R', 'R', 'R', 'R'],
['G', 'G', '.', '.'],
['.', '.', '.', '.'],
['.', '.', '.', '.']
])
// true โ there are 4 red lights in a horizontal line
hasFourInARow([
['R', 'G', 'R'],
['G', 'R', 'G'],
['G', 'R', 'G']
])
// false โ there are no 4 consecutive lights of the same color
Note: The board can be any size.
