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
- Your code has no type errors
- A frozen (readonly) array is accepted
- 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.
Press Run to see the page.
Console
Nothing printed yet.