I'm trying to get an "hourglass" array out from a nested array.
Say that this array is
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
I have to get this "hourglass" array out and add it all up:
1 1 1
1
1 1 1
Therefore, here's my attempt:
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if ((i === 1 && j === 0) && (i === 1 && j === 2)) {
continue;
} else {
newArr.push(arr[i][j]);
}
}
}
I noticed that if I use this condition: i === 1 && j === 0
, it was able to skip over the position at i = 1
and j = 0
but when I added j = 2
, I couldn't get it to skip over the first and third positions. Therefore, I was trying out various options to get it to work but I couldn't get it to work. Such, I was wondering if I'm doing the && operator
correctly?