Sample: Writing small functions
A placeholder post showing code highlighting, lists, and quotes. Replace or delete it.
This is a sample post to show how articles render. Replace it with your own writing, or delete the file.
Why small functions
Small functions are easier to name, test, and delete. When a function does one thing, its name can describe that thing exactly.
If you can’t name it, you probably don’t understand it yet.
An example
type User = { name: string; active: boolean };
export function activeNames(users: User[]): string[] {
return users.filter((u) => u.active).map((u) => u.name);
}
A few rules of thumb:
- Prefer pure functions where you can.
- Keep side effects at the edges.
- Use
constby default and reach forletonly when needed.
That’s it. Headings get anchor links, so you can link straight to why small functions.