logo CodeStepByStep logo

array_mystery6

Language/Type: PHP array mystery arrays
Author: Melissa Hovik (on 2018/01/05)

Consider the following function:

function array_mystery6($arr) {
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $arr[$i] = $arr[$i - 1] + $arr[$i + 1];
        if ($arr[$i] % 2 == 0) {
            $arr[$i] = $arr[$i] / 2;
        }
    }
    return $arr;
}

For each array below, indicate what the returned array's contents would be after the function array_mystery6 were called and passed that array as its parameter.

[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.