With 2d array like this
const initial2dArray = [['a','a','b'],['b','b','c']];
how can i create a function that removes consecutive similar elements in a row in each sub array and interchanges it with any other element in the other sub arrays repeatedly until no sub array in the 2d array contains two similar elements in a row. The output should be
const final2dArray = [['b','a','b'],['b','c','a']]
Or
[['b', 'a', 'b'], ['a', 'b', 'c']]
As far as no two elements appear more than once in a row
if the solution is available online please share link
note: