You are viewing a single comment's thread. Return to all comments →
const maxLength = arr.length; let max = -Infinity; let arrAux = Array(3); let sum = 0; const getHourglassSum = (arr) => { let sum = 0; for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { sum += arr[i][j]; } } sum = sum - arr[1][0] - arr[1][2]; return sum; }; for (let i = 0; i < maxLength - 2; i++) { for (let j = 0; j < maxLength - 2; j++) { arrAux[0] = arr[i].slice(j, j + 3); arrAux[1] = arr[i + 1].slice(j, j + 3); arrAux[2] = arr[i + 2].slice(j, j + 3); sum = getHourglassSum(arrAux); if (sum > max) max = sum; } } console.log(max);
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
JavaScript Solution