Selection Sort
12345678910111213141516
const numbers = [3,11,2,5,3,9,7,5,3];
const selectionSort = arr => {
let smallest_index = 0;
for(let i=0; i<arr.length; i++) {
for(let j=i; j<arr.length; j++) {
if(arr[j] < arr[smallest_index]) smallest_index = j;
}
[ arr[i], arr[smallest_index] ] = [ arr[smallest_index], arr[i] ];
}
}
selectionSort(numbers);
console.log(numbers);
JavaScript
INFO