Marks
Ribbons in the long book: ma leaves one, 'a opens the book at that line, `a puts you on the exact word, and '' or `` go back to where you were before the last jump.
Wednesday, 2:07 a.m. Your first week on call, and the pager wakes you: every order tonight paid the flat 1.50 delivery fee, however far the rider rode. The trail runs through legacy.js: distanceKm near the top, placeOrder and deliveryFee past the middle. You'll be going back and forth between them for the next hour.
In the long book you learned to turn to any page. Tonight you want to leave ribbons in a few.
Warm-up from earlier chapters
Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.
Leave a ribbon
ma leaves a ribbon named a at the cursor, the way a bookmark ribbon stays in a page. Wherever you go next, 'a opens the book at that ribbon again: the marked line, at its first non-blank. Any lowercase letter is a ribbon of its own, so mb leaves a second one.
function placeOrder(cart, user, now) { const order = { id: newId(), items: cart.items, address: user.address, placedAt: now.toISOString() }; const fee = deliveryFee(order, distanceKm(KITCHEN, order.address)); const problem = validateOrder(order); if (problem) throw new Error(problem); order.discount = studentDiscount(order, user); order.total = totalFor(order) - order.discount + fee; return order;}function deliveryFee(order, km) { const base = km <= 2 ? 0 : 1.5;a on the call to distanceKm, b at the start of the line above. The cursor has moved on; the ribbons stay.Ribbons left for you
While the pager rang you left two ribbons: a in deliveryFee, b in distanceKm. Each time, something pulls you to the far end of the book first. Open the book at the ribbon with 'a or 'b: two keys from anywhere, which no other route beats.
This exercise needs a keyboard. Read on, and play it at your computer.
Your own ribbons
Now leave them yourself. Go to placeOrder and leave ribbon ma before you set off; go to distanceKm and leave mb. Then back and forth: placeOrder, distanceKm, placeOrder. Any route counts; with the ribbons, each trip back is two keys.
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.
The exact word
'a opens the page; the backtick, `a, also puts your finger back on the exact word you marked: same line, same column. Use it when you'll come back to change something in the middle of a line.
Page or word?
The cursor is in order on line 2. You press ma, then G, then 'a. Where does the cursor land?
A note on the exact word
In placeOrder, put the cursor on order.address inside the call to distanceKm and leave ribbon ma there. Go and read distanceKm: it wants .lat and .lng. Then come back to the exact word with `a and leave yourself a note right in front of it: /* lat? */ .
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.
The ribbon Vim leaves for you
Every time you make a big jump (G, a search, 'a), Vim leaves a ribbon where you were. '' (two single quotes) goes back to that line; `` (two backticks) goes back to the exact spot, like `a. Press it again and you're back where you jumped to: the quickest way to look something up and return.
Look it up, come back
The cursor is on isLunchRush in deliveryFee. Look up what it does with a search for function isLunchRush, then come back to the exact word with ``.
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.
Ribbons, from memory
Press the keys.