Implement selectionSort(array) — order an array of numbers ascending using selection sort. The idea is simple: repeatedly find the smallest value in the part of the array you haven't sorted yet, and move it to the front of that unsorted part. After the first pass the smallest value sits at index 0; after the second, the next smallest sits at index 1; and so on until the whole array is in order. Return a new sorted array — do not change the array you were given.
// array: number[] — the numbers to sort (not mutated).
// returns: number[] — a NEW array with the same values, sorted ascending.
function selectionSort(array: number[]): number[];
selectionSort([3, 1, 2]);
// → [1, 2, 3]
selectionSort([64, 25, 12]);
// → [12, 25, 64]
[]; a single-element array returns a copy of itself. Already-sorted and reverse-sorted inputs must both come out sorted.Array.prototype.sort.