I am taking the course and I learn new things besides of what is written in the course.
Some of the things I see / learn I wonder how common would it be? and if they are like seen in a very particular case, or if they are more common?
Take this example:
function multiplyAll(arr) {
var 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;
}
// Modify values below to test your code
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
No, I am not taking about the nested array. More specifically I am talking about this line:
product = product * arr[i][j];
There was no way in the world I was gonna get to the arr[i] [j];
obviously I don’ remember seen a code written that way before, and WHY would it work that way?
I ask WHY would this work this way because it seems very specific.
What if you want to do a math like:
([1 +2]+[3*4]-[5+6-7])
^^ A variation of adding, substracting, multiplication, division, I would think might be more common than straight multiplication for everything.
The arr[i] [j];
looks like a pretty neat trick. I just have to remember that using a function’s argument and adding the [i][j] from the nested array will multiply everything.
Is there a trick to include a shortcut for a mix of +, - , *, /, within the formula as well?