Problems178
Search for a command to run...
Try your own input
Change the array and replay the algorithm from step one.
Current step
Selection Sort: find the minimum in the unsorted portion and place it at the sorted boundary.
Selection Sort
1function selectionSort(arr) {//i: —minIdx: —2 for (let i = 0; i < arr.length; i++) {3 let minIdx = i;4 for (let j = i + 1; j < arr.length; j++) {5 if (arr[j] < arr[minIdx]) {6 minIdx = j;7 }8 }9 if (minIdx !== i) {10 [arr[i], arr[minIdx]] = [arr[minIdx], arr[i]];11 }12 }13 return arr;14}