Results for “common”
Small, practical examples. Search by task or narrow things down below.
Name a value that stays fixed
TypeScript: Use a constant declaration or the language’s constant naming convention for a fixed limit.
TypeScript✓ Tested
Name an intermediate query with a CTE
Make a filtered result reusable within one statement.
CTE✓ Tested
Narrow a union using typeof
Handle text and numeric values with separate branches.
union✓ Tested
Normalize identifier case consistently
TypeScript: Use toLowerCase for a simple case-insensitive ASCII identifier lookup.
TypeScript✓ Tested
Pair corresponding array items by position
TypeScript: Validate equal lengths before zipping when missing counterparts would be an error.
TypeScript✓ Tested
Percent-encode one URL component
TypeScript: encodeURIComponent escapes a parameter value rather than a complete URL.
TypeScript✓ Tested
Prevent runtime changes to top-level properties
TypeScript: Object.freeze prevents ordinary top-level mutations; Reflect.set reports the rejected update without throwing.
TypeScript✓ Tested
Print a number with two decimal places
TypeScript: Format a small decimal value consistently for display.
TypeScript✓ Tested
Process the lines of an in-memory string
Java: Use String.lines to handle common line terminators without retaining them.
Java✓ Tested
Produce a lazy sequence with a generator
TypeScript: A generator yields one value per iteration without building an intermediate array.
TypeScript✓ Tested
Read a nested optional value
Avoid dereferencing a missing nested object.
optional chaining✓ Tested
Read a property with keyof
Keep the key and returned value tied to an object type.
keyof✓ Tested