We have 4 dimensional array. It is necessary to write a program that will add even its number, which is to the right, and it will be made 0, but only once.
function solution(x){ for (var i = 0; i < x.length; i++) { for (var j = 0; j < x.length; j++) { if (x[i][j]==x[i][j+1]) { x[i][j]=0 x[i][j+1]*=2 } } } return JSON.stringify(x) } console.log(solution([[2,2,4,8], [4,8,4,8], [8,8,8,8], [64,8,16,8]])) he will return
[0,0,0,16], [4,8,4,8], [0,16,0,16], [64,8,16,8] but it is necessary that the second time is not folded, that is, instead of [0,0,0,16], you need [0,4,4,8]
It is necessary that the program worked correctly for all such examples, but at that time was very simple ..