Skip to content

Commit 0b345cf

Browse files
committed
done. (incl. bonus ironhack-labs#8. Bonus ironhack-labs#4.1 still needs a fix)
1 parent 4d500ea commit 0b345cf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/functions-and-arrays.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,25 @@ const matrix = [
190190
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
191191
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
192192
];
193+
194+
const greatestProduct = (matrix) => {
195+
console.log(matrix);
196+
197+
let greatestProductSoFar = 0;
198+
199+
for(let row=0; row<matrix.length; row++){
200+
for(let col=0; col<matrix[row].length-4; col++){
201+
let productHor = matrix[row][col] * matrix[row][col+1] * matrix[row][col+2] * matrix[row][col+3];
202+
if (greatestProductSoFar<productHor) greatestProductSoFar=productHor;
203+
}
204+
}
205+
206+
for(let col=0; col<matrix[0].length; col++){
207+
for(let row=0; row<matrix[col].length-4; row++){
208+
let productVer = matrix[row][col] * matrix[row+1][col] * matrix[row+2][col] * matrix[row+3][col];
209+
if (greatestProductSoFar<productVer) greatestProductSoFar=productVer;
210+
}
211+
}
212+
213+
return greatestProductSoFar;
214+
};

0 commit comments

Comments
 (0)