Skip to content

Commit 76872ec

Browse files
committed
Bonus - Iteration ironhack-labs#8
1 parent 5306d21 commit 76872ec

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/functions-and-arrays.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,18 @@ const matrix = [
207207
[1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48]
208208
];
209209

210-
function greatestProduct(arr) {
210+
function greatestProduct(numbersArray) {
211211
let multipliedNumbers = 0
212-
let multiplyResult
213-
for (i = 0; i < arr.length - 1; i++) {
214-
for (j = 0; j < arr[i].length - 1; j++) {
215-
if (i > 0 && j > 0) {
216-
multiplyResult = arr[i - 1][j] * arr[i + 1][j] * arr[i][j + 1] * arr[i][j - 1]
217-
//console.log(`${arr[i-1][j]} * ${arr[i+1][j]} * ${arr[i][j+1]} * ${arr[i][j-1]} = ${multiplyResult}`)
212+
for (let i = 0; i + 3 < numbersArray.length; i++) {
213+
for (let j = 0; j < numbersArray[i].length; j++) {
214+
for (let k = 0, multiplyResult = 1; k <= 3; k++) {
215+
multiplyResult = (numbersArray[i + k][j]) * multiplyResult
216+
//console.log(`iteraccion ${k} -> multiplyResult = ${multiplyResult}`)
218217
if (multiplyResult > multipliedNumbers) {
219218
multipliedNumbers = multiplyResult
220-
//console.log(`multipliedNumbers = ${multipliedNumbers} / multiplyResult = ${multiplyResult}`)
221219
}
222220
}
221+
//console.log(`////`)
223222
}
224223
}
225224
return multipliedNumbers

0 commit comments

Comments
 (0)