June 2025
Intermediate to advanced
152 pages
3h 15m
English
| Practice 27 | Sort ’em Out |
If I’m typing in some kind of collection literal, and if the order of the items doesn’t matter, then I’ll sort the items.
For example, TypeScript has enumerated types:
| | enum Purple { |
| | Eggplant, |
| | Lavender, |
| | Lilac, |
| | Mauve, |
| | Rebecca, |
| | Royal, |
| | Violet, |
| | } |
I often use hashes (dictionaries) to pass in options. I sort the keys:
| | circle( |
| | fill: RED, |
| | stroke: BLACK, |
| | text: "push me", |
| | x_pos: 231, |
| | y_pos: 34, |
| | ) |
This is also a good candidate for alignment.
| | circle( |
| | fill: RED, |
| | stroke: BLACK, |
| | text: "push me", |
| | x_pos: 231, |
| | y_pos: 34, |
| | ) |
You may never feel the need to use this technique. But, even so, look for times when you accidentally duplicate an item when adding it to an existing ...
Read now
Unlock full access