Results for “Type & reading flow”
Small, practical examples. Search by task or narrow things down below.
Build an object from key-value entries
TypeScript: Object.fromEntries converts an iterable of pairs into ordinary own properties.
TypeScript✓ Tested
Calculate a page count with ceiling division
TypeScript: Use Math.ceil for a nonnegative item count and a positive page size.
TypeScript✓ Tested
Calculate a simple total
TypeScript: Multiply a unit price by a quantity, then add a delivery fee.
TypeScript✓ Tested
Calculate integers beyond Number’s precise range
TypeScript: Use BigInt operands together to avoid precision loss.
TypeScript✓ Tested
Call a library function
TypeScript: Use a standard absolute-value function with a small negative number.
TypeScript✓ Tested
Cap a box’s width
CSS: Max-width constrains an otherwise larger declared width.
CSS✓ Tested
Capture a surrounding value in a closure
Capture a surrounding value in a closure in a complete Rust program using the standard library.
Rust✓ Tested
Capture state in a closure
Capture state in a closure using a complete Go program with explicit sample inputs.
Go✓ Tested
Check an array allocation size before multiplying
C: Compare the requested element count against SIZE_MAX divided by element size.
C✓ Tested
Check array membership with includes
TypeScript: includes uses SameValueZero comparison, which also matches NaN.
TypeScript✓ Tested
Check positive integer addition before performing it
C: Check the upper boundary before adding two known nonnegative integers.
C✓ Tested
Check whether a value is a safe integer
TypeScript: Number.isSafeInteger also checks the exact-integer range supported by Number.
TypeScript✓ Tested