# Some array iteration problem.

Page 1 of 1

## 2 Replies - 608 Views - Last Post: 21 April 2013 - 12:09 AM

### #1 zhenurik

Reputation: 0
• Posts: 4
• Joined: 19-March 13

# Some array iteration problem.

Posted 20 April 2013 - 01:12 PM

Function getRowWin(arr) supposed to find '4 in a raw' - 4 the same elements together in one line in the 2 dimensional array. But for some reason it does not work.

```matrix = [  [1,2,3,4,5,6,7],
[2,3,1,7,1,1,1],
[3,2,3,4,5,6,4],
[4,2,4,4,4,4,5],
[5,2,3,4,5,6,7],
[6,2,2,2,2,6,8]
];
function getRowWin(arr){

for (var i = 0; i < 6; i++){
for (var y = 0; y < 4; y++){
if( arr[i][y] ==  arr[i][y+1] ==  arr[i][y+2]  ==  arr[i][y+3]){
console.log(arr[i][y]+' '+arr[i][y+1]+' '+arr[i][y+2]+' '+arr[i][y+3]);
}else
console.log("Nothing");
}
}
}
getRowWin(matrix);
```

Is This A Good Question/Topic? 0

## Replies To: Some array iteration problem.

### #2 andrewsw

• blow up my boots

Reputation: 6545
• Posts: 26,533
• Joined: 12-December 12

## Re: Some array iteration problem.

Posted 20 April 2013 - 01:40 PM

You need ands:

```if ( arr[i][y] ==  arr[i][y+1] && arr[i][y+1] ==  arr[i][y+2]
&& arr[i][y+2]  ==  arr[i][y+3]) {
```

### #3 zhenurik

Reputation: 0
• Posts: 4
• Joined: 19-March 13

## Re: Some array iteration problem.

Posted 21 April 2013 - 12:09 AM

andrewsw, THANK YOU!