Selection sort is like insertion sort in the way that you can think of it as dividing the array into two parts, sorted and unsorted. The sorted part will be on the left side and it will start off empty. Each pass through the array will take the smallest element that is left and add it to end of the sorted side.
function selectionSort(arr) {
for (let i = 0; i < arr.length - 1; i++) {
let min = i;
for (let j = i+1; j < arr.length; j++) {
if (arr[j] < arr[min]) {
min=j;
}
}
if (min != i) {
let tmp = arr[i];
arr[i] = arr[min];
arr[min] = tmp;
}
}
return arr;
}