Command Palette

Search for a command to run...

Hectal
Phase 5: Arrays, Tuples, Enums and Special Types
TypeScript · Exercise 1 of 6Next
Beginner

Sort Without Touching the Original

sortedCopy is supposed to return a sorted list and leave the caller's array alone, but sort reorders the array in place. The console shows both lists in the same order.

Change the parameter type so the function promises not to change its input, and fix the body so it works on a copy. The checks also call sortedCopy(Object.freeze([2, 1])), which must type-check.

What Check tests

  1. Your code has no type errors
  2. A frozen (readonly) array is accepted
  3. The console prints 1,2,3 3,1,2

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.