← All Exercises

Readonly Array Types

basictypescript~10min

Background

Readonly types enforce immutability at the type level, preventing accidental mutations of function arguments.

Problem

Write a function that takes a readonly array of numbers and returns a new sorted array without modifying the original.

Input

A readonly array of numbers (readonly number[]).

Output

A new sorted array of numbers.

Sample tests

Sample 1

Input: [3, 1, 2]
Expected: [1, 2, 3]

Your solution

Learning objective

Understand readonly array types and immutability enforcement in TypeScript.