Extract the numbers
Launch week, Wednesday: magic numbers into one CONFIG. Ranged slips that skip the config line, patterns that match a number only where it stands on its own, and qaq then :g/note:/d A to move lines into an emptied jar.
Wednesday of launch week, 9:00 a.m. The tax rate, the rush fee and the delivery radius are typed straight into the pricing code, again and again: 0.0875, 1.5, 8. Burrito 2.0 opens in a second city next month, with different numbers, so they go into one CONFIG object today.
The trick is changing every copy of a number except the one in the config itself.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Everywhere but the first line
Write the config on line 1, then send the replacements with a range that starts below it: :2,$s/0\.0875/CONFIG.tax/g. The dot needs its backslash (it's a pattern), and \< \> keep 8 from matching inside 18 or 0.0875. One careful slip per number.
const CONFIG = { tax: 0.0875 };return amount * 0.0875;const tax = subtotal * 0.0875;const CONFIG = { tax: 0.0875 };return amount * CONFIG.tax;const tax = subtotal * CONFIG.tax;The whole file?
The config line is written. You send the radius slip to the whole file, %, instead of 2,$. What does line 1 say now?
Stage 1 · The config line
9:10. Open a line above the first and write the config, followed by a blank line: const CONFIG = { tax: 0.0875, rushFee: 1.5, maxKm: 8 };
This exercise needs a keyboard. Read on, and play it at your computer.
Stage 2 · Names instead of numbers
9:30. Below the config, every 0.0875 becomes CONFIG.tax, every 1.5 CONFIG.rushFee, and every 8 CONFIG.maxKm. The config line keeps its numbers, and the kitchen's 18 minutes in etaMin isn't the radius: it stays.
Stuck? Show a hint
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Stage 3 · The notes under the config
10:00. The // note: lines above the functions belong with the numbers, right under the config line. Jar a isn't empty: it still holds the config line you copied into it at 9:10 for the team chat. Empty it with qaq (a recording of nothing), move the notes into it in one slip, :g/note:/d A (a capital label adds each line to the jar, and d takes it out of the code), then pour the jar under the config line. A jar emptied with qaq pours a blank line first: that's the gap under the config.
The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.
See ProThis exercise needs a keyboard. Read on, and play it at your computer.
Extracting, from memory
Press the keys.
order with ticket from line 2 to the end.order with ticket from line 2 to the end.