ITPEC FE Subject B April 2026 Question 13
ITPEC FE Subject B April 2026 — Question 13 of 20
The blank must read decrease i from atIndex - 1 to index.
This loop collects the name part, which lies to the left of the "@", and it builds the string with prepend:
- •start one position before the
"@", atatIndex - 1, because the"@"itself is not invalidChars - •walk backwards toward
index, the point where the previous email ended - •each valid character is prepended, so scanning right to left restores the original order
- •the first invalid character, such as a space, ends the name
For "Contact us at [email protected]" the walk starts at the "e" of doe and stops at the space before john.
Answer (a)
Why not others:
- (b) — starts at atIndex, which is the "@" itself; it is not in validChars, so the loop exits at once and candidate stays empty, meaning no email is ever collected
- (c) and (d) — walk forwards while still prepending each character, which reverses the name; they also stop at the first invalid character encountered from the left, cutting the name short or missing it entirely
Key rule: Match the direction of travel to the accumulation. prepend while moving backwards preserves order; append while moving forwards does the same. Mixing them reverses the result.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.