function A(a, b) {
return a[b] * b;
}
function B(a) {
var x = 0;
for (var i=5; i>0; i--)
x += A(a, i);
return x;
}
var aValues = [3,5,9,8,7,1];
var y = B(aValues);
Would the answer be:
B(1)
B(3)
B(5)
B(7)
B(8)
B(9)
?
Im lost be any push in the right direction would be appreciated.
After the execution y is 80.
The complete array is passed to
B(). The loop inB()iterates over the last 5 elements ofaValues. Arrays in Javascript start at index 0, so the loopi=5; i>0; i--never touches the array element with index 0Function
a()then multiplies the current item with the current index and returns the result (which is added to x)So for every loop index you get:
So after the loop x contains the value 80 which is returned and assigned to y