Learn Practice Daily golf Reference
Ex & substitution·Lesson 7 of 7·11 min·0/5 exercisesPro

Migration night

The whole of track twelve before midnight: the rename with the handbook link kept, the ids moved up by 1000 with \=submatch(0)+1000, and the docs cleaned with :g and a ranged :sort u. Then the release.

Scene

Thursday, 11:00 p.m. Migration night. The release window opens at midnight: every rider in the code becomes courier, the courier ids move up by 1000 to make room for the new system's, and the docs get tidied. One hour, three files, and no one else awake.

Every slip you write tonight goes out to every line it names. Write them carefully.

From memory

Warm-up from earlier chapters

Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.

Sort the file and drop duplicate lines.
press the keys…8 keys
1 of 2
Sort the file and drop duplicate lines.

Every slip, at a glance

Which lines: ., $, %, .,+3, a highlight, :g/pattern/ and :v/pattern/. What to do: d, s/old/new/ with its small print (g, c, i; &, \1, \u in the replacement), normal, t, m, sort. And the last slip again: &, :&&↵, g&.

Work it out, again

At 11 a.m. you turned minutes into seconds with \=, work it out: the replacement is a calculation, done for each match, and submatch(0) is the text that matched. Tonight it's ids: :%s/id: \zs\d\+/\=submatch(0)+1000/ finds each id's number (\zs starts the match at the number) and puts back the number plus 1000.

Before
{ id: 7, zone: "Wynwood" },
{ id: 12, zone: "Brickell" },
:%s/id: \zs\d\+/\=submatch(0)+1000/↵
{ id: 1007, zone: "Wynwood" },
{ id: 1012, zone: "Brickell" },
Each matched number, worked out again: 7 becomes 1007, 12 becomes 1012.
Boss round

Stage 1 · The code

11:10. riders.ts: every rider becomes courier (riders, riderId, riderReport included), and every Rider becomes Courier. One line must not change: the handbook link, because the wiki still lives at /riders/handbook. Two slips, or three.

Stuck? Show a hint:v/https/s/rider/courier/g<CR> (or :%s/rider/courier/gc<CR> and n for the link), then :%s/Rider/Courier/g<CR>
Fix the marked spots · 11 left
1// riders.ts: the people on bikes
1// handbook: https://wiki.byteburrito.test/riders/handbook (the wiki keeps this address)
2export interface Rider { id: number; name: string; zone: string; online: boolean }
3
4export function ridersOnline(riders: RidercouriersOnline(couriers: Courier[]) {
5 return riders.filter((rider) => ridercouriers.filter((courier) => courier.online);
6}
7
8export function assignRider(order: Order, riders: RiderassignCourier(order: Order, couriers: Courier[]) {
9 const rider = nearestRider(riderscourier = nearestCourier(couriers, order.address);
10 if (!rider) return refund(order, "No ridercourier) return refund(order, "No courier nearby");
11 log("assigned", rider.id, "to", order.id);
12 return { ...order, riderId: rider.id };
13}
14
15export function riderReport(riders: RidercourierReport(couriers: Courier[]) {
16 return riders.map((rider) => rider.name + ": " + ridercouriers.map((courier) => courier.name + ": " + courier.zone);
17}
NORMALLoading the editor…0.0s1:1

This exercise needs a keyboard. Read on, and play it at your computer.

Boss round

Stage 2 · The ids

11:30. couriers.ts: every id moves up by 1000; the radius numbers stay as they are. One slip that works the new number out from the old one.

Stuck? Show a hint
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Boss round

Stage 3 · The docs

11:45. zones.md: the TODO(rider) lines go, and the zones between the heading and the footer are sorted, each one once. The heading, the blank lines and the footer stay exactly where they are, so choose the sort's lines with care. Two slips.

Stuck? Show a hint
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.

Midnight: the releaseFinish the exercise above to see it.
From memory

The whole track, from memory

Eight slips from today.

Delete this line and the one below.
scroll here, then press the keys7 keys
1 of 8
Delete this line and the one below.

Extra practice optional

The chapter is done. These rounds keep going as long as you like: stop whenever it stops being useful.

Endless

Slips, endlessly

Endless Ex jobs: renames, purges, sorts and semicolons.

Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.