Unit 8 Assessment Question 4

In Unit 8 Assessment Question 4, the explanation about the answer seems to be incorrect. This part is wrong: " temp (8 ) is greater than the value at index - 1 (11 )", as a result the subsequent steps are incorrect. However, the answer seems to be correct.

Below is what I came up with - please correct me if I got it wrong:
The array after the first iteration in the for loop is unchanged.
In the second for-loop iteration:
The array after the first pass in while-loop is [ 11, 8, 8, 7, 21, 15, 1]
The array after the second pass in the while-loop is [11, 11, 8, 7, 21, 15, 1]
After existing the while loop, nums.set(index, temp) sets the first element to 12, hence the array becomes [12, 11, 8, 7, 21, 15, 1]. This is the result of executing the for loop twice.

1 Like

Hi Bonnie,
yes, I agree with you, answer C is correct, but the explanation has an issue, which is what you have highlighted-- 8 is not greater than 11 so the while loop will not run at all on the first pass of the for loop.

Thank you for making note of this issue, I am going to pass this onto support@code.org so that they can update the explanation.


1 Like