Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jhserodio/79926cbfef53d8215f1fc47704525488 to your computer and use it in GitHub Desktop.
Save jhserodio/79926cbfef53d8215f1fc47704525488 to your computer and use it in GitHub Desktop.
```javascript=
const firstInt = [
[1,1,1,0,0,0],
[0,1,0,0,0,0],
[1,1,1,0,0,0],
[0,0,0,2,0,1],
[0,0,0,0,2,0],
[0,0,0,2,3,9]
];
const sencondInt = [
[1,1,1,0,0,0,2,-8,9],
[0,1,0,0,0,0,0,2,0],
[1,1,1,0,0,0,-9,9,1],
[0,0,0,2,0,1,0,0,2],
[0,0,0,0,2,0,0,0,0],
[0,0,0,2,3,9,0,0,0],
[0,0,0,0,0,0,2,3,9],
[0,0,0,0,0,0,0,-9,0],
[0,0,0,0,0,0,2,3,9],
];
const carambolas2D = arr => {
let listinha = []
for (let i = 0; i < arr.length; i++){
for (let j = 0; j < arr[i].length; j++) {
if ((arr[i + 2][j + 2] !== undefined) && (i < arr.length - 2)) {
let somatuto =
arr[i][j] +
arr[i][j + 1] +
arr[i][j + 2] +
arr[i + 1][j + 1] +
arr[i + 2][j] +
arr[i + 2][j + 1] +
arr[i + 2][j + 2];
listinha.push(somatuto);
} else {
console.log('num tem')
}
}
}
// return listinha.reducer((valAnt, valAtu) => valAnt > valAtu ? valAnt : valAtu);
return listinha;
}
console.log(carambolas2D(firstInt));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment