3 ms·
The final version of sortNumbers is: function sortNumbers(array: Readonly<Array<number>>) { return [...array].sort((a, b) => a - b) } And sort s
by genezeta 5y ago
The final version of sortNumbers is:
function sortNumbers(array: Readonly<Array<number>>) {
return [...array].sort((a, b) => a - b)
}
And sort sorts in place and then returns the sorted array[0]. So here the newly created [...array] is sorted and then returned by sort and then by the return at the start of that line.
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...