Skip to main content
๐Ÿ“œ WAYPOINT LESSON

From spec to code

โญ beginnerโณ 10 min read๐Ÿ“ Lesson 47 of 256

Mechanical translation of FRQ spec sentences, guard-first structure.

Reading a spec is a skill of its own. FRQ wording translates mechanically:

| Spec sentence | Code | | --- | --- | | "returns true if..." | return <condition>; โ€” no if needed | | "the number of..." | accumulator loop over the data | | "if it is not possible, return..." | guard clause first | | "helper methods may be called" | use them โ€” the grid of provided helpers is a gift | | "prepends"/"appends" | order of concatenation: s + rest vs rest + s | | "in no particular order" | any order accepted โ†’ keep yours simple |

A complete FRQ 2 answer is usually 5โ€“15 lines: the constructor copies parameters into fields (watch for this.x = x), and each method guards, loops, accumulates, returns. Nothing else.

Write tests from the spec, not from your code: every "returns -1 if absent" sentence is one test case; every boundary in the spec ("between 0 and 100 inclusive") is two more.

โšก Now practice

Ready to Code
Design repsState machines, delegation, spec fidelity, class debugging.
5 challenges ยท ยท ~60 min