File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -236,3 +236,28 @@ const greatestProduct = (matrix) => {
236
236
}
237
237
return maximunProduct
238
238
}
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
+ }
You can’t perform that action at this time.
0 commit comments