1function selectionSort(arr) {
2 const a = [...arr];
3 const n = a.length;
4 for (let i = 0; i < n - 1; i++) {
5 let minIndex = i;
6 for (let j = i + 1; j < n; j++) {
7 if (a[j] < a[minIndex]) {
8 minIndex = j;
9 }
10 }
11 if (minIndex !== i) {
12 [a[i], a[minIndex]] = [a[minIndex], a[i]];
13 }
14 }
15 return a;
16}