logo CodeStepByStep logo

arrayMystery10

Language/Type: JavaScript arrays array mystery
Author: Melissa Hovik (on 2017/08/14)

What are the resulting values of the following arrays after passing each as an argument to the function below?

function arrayMystery10(arr) {
    for (let i = 1; i < arr.length - 1; i++) {
        arr[i] = arr[i - 1] + arr[i + 1];
        if (arr[i] % 2 == 0) {
            arr[i] = arr[i] / 2;
        }
    }
}
[42]
[1, 0, 0, 1, 0]
[1, 3, 4, 6]
[8, 13, 0, 6, 11, 2]
[1, 1, 2, 3, 5, 8, 13]

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.