Results for “Functions & types”
Small, practical examples. Search by task or narrow things down below.
Count days between UTC-midnight dates
TypeScript: A day is exactly 86400000 milliseconds for these explicitly UTC-midnight inputs.
TypeScript✓ Tested
Count the items in a collection
TypeScript: Read the collection’s length instead of hard-coding the loop limit.
TypeScript✓ Tested
Count Unicode code points in a string
TypeScript: String iteration combines surrogate pairs, unlike the UTF-16 length property.
TypeScript✓ Tested
Create a modified copy of an immutable record
C#: A with expression creates a shallow copy with selected changed properties.
C#✓ Tested
Create a STRICT table
Require values compatible with declared column types.
STRICT✓ Tested
Create independent rows in a matrix
TypeScript: Use a mapping function to create each row instead of sharing one array with fill.
TypeScript✓ Tested
Decode a percent-encoded URL component
TypeScript: decodeURIComponent reverses percent encoding and throws for malformed sequences.
TypeScript✓ Tested
Delegate iteration to another iterable
TypeScript: yield-star forwards items from another iterable while retaining generator composition.
TypeScript✓ Tested
Detect an invalid Date object
TypeScript: An invalid Date has a NaN time value.
TypeScript✓ Tested
Detect NaN without converting the input
TypeScript: Number.isNaN tests the special numeric value instead of applying string-to-number conversion.
TypeScript✓ Tested
Dispatch values with wildcard patterns
PowerShell: Switch -Wildcard interprets shell-style matching patterns for each clause.
PowerShell✓ Tested
Display a number with a fixed decimal width
TypeScript: toFixed returns a formatted string rather than a numeric value.
TypeScript✓ Tested