Table of Contents
Month 1 · Week 2 — Exercises¶
Practice for composite types: slices, maps/sets, and strings/runes. Each folder is its own package with a solution and table-driven tests. Standard library only.
| Exercise | Concept | Day | Run tests |
|---|---|---|---|
wordfreq/ |
maps, comma-ok, deterministic sort | 011 | go test ./wordfreq |
dedup/ |
slices, map[T]struct{} set, generics |
009–011 | go test ./dedup |
runereverse/ |
runes vs bytes, UTF-8 | 012 | go test ./runereverse |
How to use¶
- Try it yourself first — move the solution aside and re-implement from the prompt.
- Run
go test ./...from this directory. - Log any differences in your day note's "Mistakes" section.
Prompts¶
- wordfreq:
Count(text) map[string]int— case-insensitive, split on non-alphanumerics.Top(text, n) []string— n most frequent, ties broken alphabetically (deterministic). - dedup:
Dedup[T comparable](s []T) []T— drop duplicates, keep first-seen order, do not mutate the input. Bonus:DedupInPlacereusing the backing array (s[:0]). - runereverse:
Reverse(s string) stringreversing by rune, not byte, so multi-byte characters survive. Bonus:IsPalindromeRunes,RuneCount.
Results¶
| Exercise | Status | Tests |
|---|---|---|
| wordfreq | ✅ | pass |
| dedup | ✅ | pass |
| runereverse | ✅ | pass |
Run all of Week 2 at once with
go test ./....