Learn Practice Daily golf Reference
Search·Lesson 1 of 6·8 min·0/6 exercisesPro

/ ? n N

Search is a metal detector: / or ?, a few letters and ↵ jump to the next match, then n and N walk to the next and previous one.

Scene

Monday, 8:40 a.m. Dispatch replays Friday's last delivery for you: the rider followed the app to the harbour, to the very edge of the water, and handed two burritos to a confused fisherman. (The app wanted somewhere far out to sea; the harbour is as far as a bike goes.) Somewhere in the delivery code a latitude and a longitude have swapped places.

There are hundreds of numbers in those files. You don't read a beach to find a coin; you sweep it with a metal detector.

From memory

Warm-up from earlier chapters

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

To the middle of the screen.
press the keys…
1 of 2
To the middle of the screen.

Tune it, sweep

/ opens a search at the bottom of the editor: type what you're looking for (the pattern) and every match lights up as you type, like a detector beeping over every coin of that kind. ↵ sweeps forward and stops at the first match after the cursor.

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

The next beep

The detector keeps the tune. n walks on to the next match, N walks back to the previous one, and at the end of the file the sweep carries on from the top. One search, then n n n past every match in the file.

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

Sweep the other way

? searches backwards, up the file. After a ?, n keeps going up and N comes back down: the same direction as the sweep, exactly like ; after F. Use ? when what you want is above you.

Tune it just enough

You don't need the whole word, only enough letters that nothing closer matches. /Wy finds Wynwood in four keys; /Wynwood takes nine. Type a couple of letters, watch the highlight, and press ↵ as soon as the right match is the next one.

Try it

Sweep for it

Each target starts a word. Search for it with / or ?, as few letters as you can, then ↵. n and N for the next one along.

1 of 6Move the cursor onto the
1export class Kitchen {
1 private queue: Order[] = [];
2 private busy = false;
3
4 enqueue(order: Order) {
5 this.queue.push(order);
6 this.startNext();
7 }
8
9 startNext() {
10 if (this.busy || this.queue.length === 0) return;
11 this.busy = true;
12 const next = this.queue.shift();
13 cook(next).then(() => this.finish());
14 }
15}
NORMALLoading the editor…1/60.0s1:1

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

Check yourself

Which way is next?

1const fee = zone.fee;
1const rush = fee * 2;
2log("fee", fee);
NORMAL
Keys pressed: /fee↵N

The cursor is at the start of line 1. You search with /fee and ↵, then press N. Where does the cursor end up?

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

Sweeps, from memory

Press the keys.

Search forward for order.
scroll here, then press the keys7 keys
1 of 4
Search forward for order.
Challenge

Sweep the codebase

Twelve targets across the codebase. Search for each with as few letters as you can; n and N when the next one along is the one you want.

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

The zones file

zones.ts, where the coordinates live. Dispatch reads out six places in their order; the goal bar says what to check when you get there. A short search each; some are behind you, so ? or N.

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.

Zones: cleanFinish the exercise above to see it.

Extra practice optional

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

Endless

Beachcombing

Endless targets on word starts. Tune it, sweep, next.

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.