I truly don’t understand this answer. Can someone help explain this to me?
How long does it take a beginner to usually finish the first 100 tasks of java?
**Your code so far**
function multiplyAll(arr) {
let product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36
The key here since it needs to multiply everything is the accumulator and in this case the product variable that starts with a value of 1. Since, any number multiplied by 1 would have the same value.
Now, on the loops there is the inner loop (with variable of j) and the outer loop (with a variable of i).
The inner loop (with the variable j) would multiply the inner arrays one value at a time. [1,2], [3,4], [5,6,7]
And the outer loop (with the variable i) would move to the next array to be used by the inner loop above. For example on the first loop for the outer loop
it will use [1,2] which then goes to the inner loop
the next iteration would be [3,4]
and the last iteration would be [5,6,7]