logo CodeStepByStep logo

2DArrayMystery1

Language/Type: JavaScript arrays array mystery multi-dimensional arrays

Consider the following function:

function mystery2darray(a) {
    for (let r = 0; r < a.length; r++) {
        for (let c = 0; c < a[0].length - 1; c++) {
            if (a[r][c + 1] > a[r][c]) {
                a[r][c] = a[r][c + 1];
            }
        }
    }
}

If a two-dimensional array named numbers is initialized to store the following integers, what are its contents after the call shown?

let numbers = [
    [3, 4, 5, 6],
    [4, 5, 6, 7],
    [5, 6, 7, 8]
];
mystery2darray(numbers);
numbers[0][0]
numbers[0][1]
numbers[0][2]
numbers[0][3]
numbers[1][0]
numbers[1][1]
numbers[1][2]
numbers[1][3]
numbers[2][0]
numbers[2][1]
numbers[2][2]
numbers[2][3]

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.