Skip to content

Commit 0661683

Browse files
Bonus - Iteration ironhack-labs#8.1: Product of diagonals completed
1 parent cec8555 commit 0661683

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/functions-and-arrays.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,28 @@ const greatestProduct = (matrix) => {
236236
}
237237
return maximunProduct
238238
}
239+
240+
//Bonus - Iteration #8.1: Product of diagonals
241+
242+
const greatestProductOfDiagonals = (matrix) => {
243+
244+
let maximunProduct = 0
245+
246+
for (let i = 0; i < matrix.length - 4; i++) {
247+
for (let j = 0; j <= matrix[i].length ; j++ ) {
248+
let checkHorizontal = matrix[i][j] * matrix[i + 1][j + 1] * matrix[i + 2][j + 2] * matrix[i + 3][j + 3]
249+
if ( checkHorizontal > maximunProduct){
250+
maximunProduct = checkHorizontal;
251+
}
252+
}
253+
}
254+
for (let i = 0; i < matrix.length - 4; i++) {
255+
for (let j = 0; j <= matrix[i].length; j++ ) {
256+
let checkVertical = matrix[i][j] * matrix[i + 1][j - 1] * matrix[i + 2][j - 2] * matrix[i + 3][j - 3]
257+
if ( checkVertical > maximunProduct){
258+
maximunProduct = checkVertical;
259+
}
260+
}
261+
}
262+
return maximunProduct
263+
}

0 commit comments

Comments
 (0)