Complete worked example
typescript
function sorted(values: readonly number[]): number[] {
return [...values].sort((a, b) => a - b);
}
const original = [3, 1, 2];
const ordered = sorted(original);- Reasoning
- Copying protects caller order while the readonly parameter prevents accidental mutating methods.