Learn Practice Daily golf Reference
Search·Lesson 4 of 6·6 min·0/5 exercisesPro

Offsets

Stand a step from the match: /lat/e lands on its end, /lat/e+3 three past it, /lat/s+2 from its start, /lat/+1 on the line below, and n keeps the stance.

Scene

Monday, 1:30 p.m. Dispatch's check: every longitude in zones.ts should be about -80. Searching for lng: lands you on the l of the word, and what you want is the number, which starts two characters after the colon.

You could search and then step. Or you could tell the detector where to put your feet.

From memory

Warm-up from earlier chapters

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

Copy from here back up to the previous user.
press the keys…7 keys
1 of 2
Copy from here back up to the previous user.

Stand at the far edge

Add /e after the pattern and the search lands on the end of the match instead of its start: /lng/e puts you on the g. Add a number to step past it: /lng: /e+1 lands one step past the space after the colon, on the first character of the number.

{ name: "Wynwood", lat: 25.8005, lng: -80.1994 },/lat↵/lat/e↵/lat/e+3↵
One search, three stances: on the match, on its last letter, three steps past it.

From the near edge, or the line below

/lat/s+2 counts from the start of the match instead (b means the same as s), and a minus counts backwards: /lat/s-2 stands two characters before it. A bare number is a line offset: /lat/+1 lands at the start of the line below the match.

Keep the stance

The best part: n and N keep the offset. Search once with /lng: /e+1 and every n after that lands on the next longitude's number, not on the word. And //e reuses the last pattern with a new offset, without retyping it.

1// delivery zones: where riders go, and what it costs to get there
1export const ZONES = [
2 { name: "Little Havana", lat: 25.7656, lng: -80.219, fee: 2.5 },
3 { name: "Brickell", lat: 25.7663, lng: -80.1917, fee: 2 },
4 { name: "Wynwood", lat: 25.8005, lng: -80.1994, fee: 3 },
5 { name: "Coral Way", lat: 25.7505, lng: -80.2409, fee: 3.5 },
6 { name: "Downtown", lat: 25.7743, lng: -80.1937, fee: 1.5 },
7 { name: "Edgewater", lat: 25.8001, lng: -80.1887, fee: 3 },
8];
9
10export function zoneFor(lat: number, lng: number) {
11 return ZONES.find((z) => Math.abs(z.lat - lat) < 0.01 && Math.abs(z.lng - lng) < 0.01);
12}
NORMALLoading the editor…1:1
Try it

Every longitude

Land on the first character of each longitude, top to bottom. One search with an offset, then n does the rest.

1 of 6Move the cursor onto the
1// delivery zones: where riders go, and what it costs to get there
1export const ZONES = [
2 { name: "Little Havana", lat: 25.7656, lng: -80.219, fee: 2.5 },
3 { name: "Brickell", lat: 25.7663, lng: -80.1917, fee: 2 },
4 { name: "Wynwood", lat: 25.8005, lng: -80.1994, fee: 3 },
5 { name: "Coral Way", lat: 25.7505, lng: -80.2409, fee: 3.5 },
6 { name: "Downtown", lat: 25.7743, lng: -80.1937, fee: 1.5 },
7 { name: "Edgewater", lat: 25.8001, lng: -80.1887, fee: 3 },
8];
9
10export function zoneFor(lat: number, lng: number) {
11 return ZONES.find((z) => Math.abs(z.lat - lat) < 0.01 && Math.abs(z.lng - lng) < 0.01);
12}
NORMALLoading the editor…1/60.0s1:1

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

Check yourself

Where do your feet go?

1{ name: "Wynwood", lat: 25.8005, lng: -80.1994 },
NORMAL
Keys pressed: /lat/e↵

You search with /lat/e and ↵. Which character is the cursor on?

Pick an answer (or press its number), then watch the engine prove it.
From memory

Stances, from memory

Press the keys.

Search for order, landing on its last letter.
scroll here, then press the keys9 keys
1 of 4
Search for order, landing on its last letter.
Boss round

Every fee

Dispatch wants the fees read out while you're here: land on the first digit of every fee in zones.ts, top to bottom. One of them changes today: the bridge on the way to Coral Way is closed, so its fee goes up to 4. Change it when you land there. Plant your feet once (the offset), then let n keep the stance.

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.