Results for “Types & reliable control flow”
Small, practical examples. Search by task or narrow things down below.
Write a generic slice helper
Write a generic slice helper using a complete Go program with explicit sample inputs.
Go✓ Tested
Allow a long flex child to shrink inside its container
CSS: Min-width zero removes the default content-size floor so local overflow handling can take effect.
CSS✓ Tested
Allow several selected options
HTML: A multiple select exposes each selected option as a value with the same control name.
HTML✓ Tested
Average a fixed set of readings
Accumulate sample values without overflowing a 16-bit total.
array✓ Tested
Await several independent results
Preserve input order while awaiting multiple promises.
Promise.all✓ Tested
Blink without blocking the loop
Use elapsed millis time instead of delay for a repeating action.
millis✓ Tested
Calculate a least common multiple using a GCD
C: Divide before multiplying to reduce the risk of intermediate overflow.
C✓ Tested
Calculate a two-dimensional vector length
C++: hypot avoids unnecessary intermediate overflow in the sum of squares.
C++✓ Tested
Calculate beyond the long integer range
Java: Use BigInteger when a fixed-width primitive type would overflow.
Java✓ Tested
Check a literal suffix in C++17
C++: Check lengths before subtracting to avoid an unsigned underflow.
C++✓ Tested
Choose a service’s internal hostname
Docker / Compose: hostname controls the name reported inside the container.
Docker / Compose✓ Tested
Choose an action with switch
Map a small command value to a result.
switch✓ Tested