B. measure block must not contain variable declarations
C. Cannot append to a constant array inside measure block
D. Array must be declared outside measure block
Solution
Step 1: Check array declaration
The array is declared with let, making it immutable (constant).
Step 2: Identify mutation attempt
Calling append(4) tries to change the constant array, causing a compile error.
Final Answer:
Cannot append to a constant array inside measure block -> Option C
Quick Check:
Appending to let array = D [OK]
Hint: Use var for arrays you want to change inside measure [OK]
Common Mistakes:
Thinking measure forbids variable declarations
Assuming array must be outside measure
Ignoring let vs var immutability
5. You want to measure the performance of sorting a large array but avoid including array creation time in the measurement. Which is the best way to write the test using measure?
hard
A. Create the array outside measure, then sort inside measure
B. Create the array inside the measure block, then sort it
C. Create and sort the array outside measure, then print inside measure
D. Create the array inside measure, but sort outside measure
Solution
Step 1: Understand what to measure
We want to measure only sorting time, not array creation time.
Step 2: Place array creation outside measure
Creating the array outside measure ensures creation time is excluded.
Step 3: Sort inside measure block
Sorting inside measure captures only sorting performance.
Final Answer:
Create the array outside measure, then sort inside measure -> Option A
Quick Check:
Exclude setup, measure only sorting = B [OK]
Hint: Put setup outside measure, test only target code inside [OK]
Common Mistakes:
Including setup time inside measure
Measuring nothing inside measure
Sorting outside measure by mistake
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.