Results for “Functions & types”
Small, practical examples. Search by task or narrow things down below.
Find the position of a matching item
TypeScript: findIndex returns -1 when the predicate matches nothing.
TypeScript✓ Tested
Find what remains after division
TypeScript: Use the remainder operator to count items left after forming complete groups.
TypeScript✓ Tested
Flatten a single nesting level
TypeScript: flat defaults to a depth of one and creates a new array.
TypeScript✓ Tested
Format whole seconds as hours minutes and seconds
TypeScript: Use integer divisions and remainders for a nonnegative duration.
TypeScript✓ Tested
Generate a bounded integer range
TypeScript: Array.from supplies each output position to its mapping function.
TypeScript✓ Tested
Group records into map entries
TypeScript: Initialize an array for a missing Map key before appending its values.
TypeScript✓ Tested
Handle an expected child-process failure
Python: Catch CalledProcessError when check=True reports a nonzero exit status.
Python✓ Tested
Handle three possible outcomes
TypeScript: Check high, normal and low values with an ordered conditional chain.
TypeScript✓ Tested
Inspect a value’s type
Inspect a value’s type using a complete Go program with explicit sample inputs.
Go✓ Tested
Inspect both successful and failed promise results
TypeScript: allSettled preserves input order and reports failures without rejecting the combined promise.
TypeScript✓ Tested
Inspect the parsed pieces of a URL
TypeScript: Use URL properties rather than splitting a URL at punctuation.
TypeScript✓ Tested
Iterate with array indices and values
TypeScript: entries provides each position and value without a separate counter.
TypeScript✓ Tested