Array.prototype.toSortedintermediateconst original = ['c', 'a', 'b']
const sorted = original.toSorted()
original // β ['c', 'a', 'b'] (unchanged)
sorted // β ['a', 'b', 'c']toSorted() is the immutable counterpart of sort() β the original array is never changed.
Unlike sort, toSorted never mutates the original array. The original remains unchanged after the call.
Implement checkSortedImmutable which calls toSorted() but returns the original array, proving it was not changed.