FIND YOUR NEXT FEW LINES

The snippet library.

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

10 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
TypeScriptArray restructuring

Concatenate arrays without mutating either input

TypeScript: concat creates a shallow combined sequence.

TypeScript✓ Tested
TypeScriptArray restructuring

Create independent rows in a matrix

TypeScript: Use a mapping function to create each row instead of sharing one array with fill.

TypeScript✓ Tested
TypeScriptArray restructuring

Flatten a single nesting level

TypeScript: flat defaults to a depth of one and creates a new array.

TypeScript✓ Tested
TypeScriptArray restructuring

Generate a bounded integer range

TypeScript: Array.from supplies each output position to its mapping function.

TypeScript✓ Tested
TypeScriptArray restructuring

Keep both matching and rejected values

TypeScript: Use two explicit outputs when a caller needs both sides of a classification.

TypeScript✓ Tested
TypeScriptArray restructuring

Map items to multiple output values

TypeScript: flatMap combines mapping and a one-level flattening operation.

TypeScript✓ Tested
TypeScriptArray restructuring

Replace an array segment in place

TypeScript: splice returns removed items and inserts replacements at the chosen position.

TypeScript✓ Tested
TypeScriptArray restructuring

Reverse a copy while preserving the original

TypeScript: Copy before reverse because reverse mutates the array it receives.

TypeScript✓ Tested
TypeScriptArray restructuring

Split an array into bounded batches

TypeScript: Advance by a positive batch size and allow a shorter final chunk.

TypeScript✓ Tested