FIND YOUR NEXT FEW LINES

Results for “type”

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

218 snippets foundClear filters
TypeScriptGetting Started

Call a library function

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

TypeScript✓ 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
TypeScriptArray traversal & selection

Check array membership with includes

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

TypeScript✓ 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
TypeScriptText handling & Unicode

Check whether text ends with a suffix

TypeScript: Use endsWith for a literal case-sensitive ending.

TypeScript✓ Tested
TypeScriptText handling & Unicode

Check whether text starts with a prefix

TypeScript: Use startsWith for a literal case-sensitive prefix comparison.

TypeScript✓ Tested
TypeScriptGetting Started

Choose between two branches

TypeScript: Use if and else to handle an available or empty stock count.

TypeScript✓ Tested
TypeScriptNumbers & numeric validation

Clamp a number between inclusive bounds

TypeScript: Combine Math.min and Math.max when lower is no greater than upper.

TypeScript✓ Tested
TypeScriptPromises & iteration protocols

Clean up a generator after an early break

TypeScript: Breaking a for-of loop closes a generator and runs its finally block.

TypeScript✓ Tested