FIND YOUR NEXT FEW LINES

Results for “Functions & data types”

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

787 snippets foundClear filters
Docker / ComposeNetworks & volume metadata

Assign a network-scoped alias

Docker / Compose: An alias gives an endpoint an additional name on that network.

Docker / Compose✓ Tested
Docker / ComposeNetworks & volume metadata

Attach an existing container to another network

Docker / Compose: network connect adds an attachment without recreating the container.

Docker / Compose✓ Tested
jQueryEvent control

Attach configuration when registering a handler

jQuery: event.data carries the registration-time data object.

jQuery✓ Tested
PythonFunctions & error handling

Avoid a shared mutable default argument

Python: Create a fresh list inside the function when the optional argument is omitted.

Python✓ Tested
TypeScriptRegular expressions & URL encoding

Build a URL query string from values

TypeScript: URLSearchParams handles query escaping and repeated parameter appends.

TypeScript✓ Tested
TypeScriptObject behavior & collections

Build an object from key-value entries

TypeScript: Object.fromEntries converts an iterable of pairs into ordinary own properties.

TypeScript✓ Tested
PythonFunctions & error handling

Cache repeated pure function calls

Python: Use lru_cache to avoid recomputing results for identical hashable arguments.

Python✓ Tested
TypeScriptNumbers & numeric validation

Calculate a page count with ceiling division

TypeScript: Use Math.ceil for a nonnegative item count and a positive page size.

TypeScript✓ Tested
TypeScriptGetting Started

Calculate a simple total

TypeScript: Multiply a unit price by a quantity, then add a delivery fee.

TypeScript✓ Tested
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