FIND YOUR NEXT FEW LINES

Results for “Types & reliable control flow”

Small, practical examples. Search by task or narrow things down below.

308 snippets foundClear filters
TypeScriptArray restructuring

Calculate differences between adjacent readings

TypeScript: Slice off the first value and compare each remaining value with its predecessor.

TypeScript✓ Tested
TypeScriptNumbers & numeric validation

Calculate integers beyond Number’s precise range

TypeScript: Use BigInt operands together to avoid precision loss.

TypeScript✓ Tested
TypeScriptGetting Started

Call a library function

TypeScript: Use a standard absolute-value function with a small negative number.

TypeScript✓ Tested
CSSBox dimensions & overflow

Cap a box’s width

CSS: Max-width constrains an otherwise larger declared width.

CSS✓ Tested
RustFunctions & data types

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
GoFunctions & types

Capture state in a closure

Capture state in a closure using a complete Go program with explicit sample inputs.

Go✓ Tested
CDynamic memory & ownership

Check an array allocation size before multiplying

C: Compare the requested element count against SIZE_MAX divided by element size.

C✓ Tested
TypeScriptArray traversal & selection

Check array membership with includes

TypeScript: includes uses SameValueZero comparison, which also matches NaN.

TypeScript✓ Tested
CNumeric parsing & arithmetic

Check positive integer addition before performing it

C: Check the upper boundary before adding two known nonnegative integers.

C✓ Tested
TypeScriptNumbers & numeric validation

Check whether a value is a safe integer

TypeScript: Number.isSafeInteger also checks the exact-integer range supported by Number.

TypeScript✓ Tested
TypeScriptArray traversal & selection

Check whether any item matches

TypeScript: some stops once a predicate succeeds.

TypeScript✓ Tested
TypeScriptArray traversal & selection

Check whether every item matches

TypeScript: every stops at the first failed predicate and returns true for an empty array.

TypeScript✓ Tested