functionselectionSort(array) {
// Loop through the arrayfor (let i = 0; i < array.length - 1; i++) {
// Keep track of unsorted elelmentlet minIndex = i;
// Loop through the rest of the array to find the smallest elementfor (let j = i + 1; j < array.length; j++) {
// Smaller element found so update minif (array[j] < array[minIndex]) {
minIndex = j;
}
}
// Smallest element isn't the one we are at, swap themif (minIndex !== i) {
[array[i], array[minIndex]] = [array[minIndex], array[i]];
}
}
return array;
}